forked from lisaogren/axios-cache-adapter
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
176 lines (161 loc) · 4.13 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
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'
let entry = './src/index.js'
// List external dependencies
const dependencies = [
'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'
entry = './src/index.node.js'
}
const polyfillExclusions = [
'es6.array.filter',
'es6.array.for-each',
'es6.array.index-of',
'es6.array.is-array',
'es6.array.map',
'es6.array.some',
'es6.date.now',
'es6.date.to-string',
'es6.number.constructor',
'es6.object.define-properties',
'es6.object.define-property',
'es6.object.keys',
// 'es6.object.to-string', // Build is broken because of this exclusion on mac.. Why?!
'es6.promise',
// 'es6.regexp.exec',
'es6.regexp.match',
'es6.regexp.to-string',
'es6.string.iterator',
'es6.string.trim',
'web.dom.iterable'
]
// 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,
output: {
path: path.resolve(__dirname, 'dist'),
filename,
library: 'axiosCacheAdapter',
libraryTarget: 'umd'
},
mode,
module: {
rules: [
{
test: /\.js$/,
// exclude: /node_modules/,
include: [
path.resolve(__dirname, 'src'),
path.resolve(__dirname, 'node_modules/cache-control-esm')
],
use: [{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
exclude: polyfillExclusions,
include: ['transform-classes']
}]
]
}
}]
}
]
},
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|\utilities.spec\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
// exclude: polyfillExclusions,
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