forked from lisaogren/axios-cache-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
161 lines (147 loc) · 3.68 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const cwd = process.cwd()
// Base filename and version variable to store what kind of version we'll be generating
let filename = 'cache[version].js'
let version = ['']
// Start with empty list of plugins and externals and an undefined devtool
const plugins = []
let externals = {}
let mode = 'development'
let target = 'web'
// List external dependencies
const dependencies = [
'lodash/isEmpty',
'lodash/isString',
'lodash/isFunction',
'lodash/size',
'lodash/find',
'lodash/map',
'lodash/merge',
'lodash/omit',
'axios'
]
dependencies.forEach(dep => {
externals[dep] = {
umd: dep,
amd: dep,
commonjs: dep,
commonjs2: dep
}
})
if (process.env.NODE_BUILD_FOR === 'node') {
version.push('node')
target = 'node'
}
// Check if we should make a minified version
if (process.env.NODE_ENV === 'production') {
version.push('min')
mode = 'production'
}
// Generate actual filename
// cache.js || cache.min.js || cache.node.js || cache.node.min.js
filename = filename.replace('[version]', version.join('.'))
// Webpack config
const build = {
entry: ['./src/index.js'],
output: {
path: path.resolve(__dirname, 'dist'),
filename,
library: 'axiosCacheAdapter',
libraryTarget: 'umd'
},
mode,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
exclude: [
'es6.promise',
'web.dom.iterable',
'es6.string.iterator',
'es6.array.index-of',
'es6.date.now',
'es6.regexp.match',
'es6.array.filter'
]
}]
]
}
}]
}
]
},
externals,
plugins,
devtool: 'source-map',
target
}
// TEST CONFIG
const test = {
entry: ['test/main.js'],
output: {
path: path.join(cwd, '.tmp'),
filename: 'main.js'
},
resolve: {
modules: ['node_modules', '.']
},
mode: 'development',
module: {
rules: [
// Transpile ES2015 to ES5
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage'
}]
]
}
}
]
},
{
test: /\.js$/,
use: {
loader: 'istanbul-instrumenter-loader',
options: { esModules: true }
},
enforce: 'post',
exclude: /node_modules|\.spec\.js$/
},
// Load font files
{ test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/, loader: 'file-loader' },
{ test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader' }
]
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin()
],
devServer: {
// contentBase: path.join(__dirname, 'public'), // boolean | string | array, static file location
compress: true, // enable gzip compression
historyApiFallback: true, // true for index.html upon 404, object for multiple paths
hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin
https: false, // true for self-signed, object for cert authority
noInfo: true, // only errors & warns on hot reload
port: 3000
},
target: 'web',
devtool: 'inline-source-map'
}
module.exports = process.env.NODE_ENV === 'test' ? test : build