forked from commenthol/date-holidays
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
82 lines (75 loc) · 1.87 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
/**
* Run with `npm run webpack`
*/
const path = require('path')
const webpack = require('webpack')
const { createVariants } = require('parallel-webpack')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const rimraf = require('rimraf').sync
const doAnalyze = process.env.npm_lifecycle_event === 'webpack:analyze'
const variants = doAnalyze
? {
target: ['commonjs2']
}
: {
minified: [true],
target: [
['commonjs2', 'index'],
['umd', 'umd']
]
}
rimraf('./dist')
function createConfig (options) {
const plugins = [
// ---- do not bundle moment locales
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// ---- do not bundle astronomia vsop planet data
new webpack.IgnorePlugin(/^\.\/vsop87B[^e].*$/)
// ---- using a custom set of timezones
// new webpack.NormalModuleReplacementPlugin(
// /moment-timezone\/data\/packed\/latest\.json/,
// require.resolve('./timezones.json')
// )
]
if (doAnalyze) {
plugins.push(new BundleAnalyzerPlugin())
}
return {
mode: 'production',
devtool: 'sourcemap',
entry: {
'date.holidays': [
'@babel/polyfill',
'./src/index.js'
]
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: options.target[1] +
(options.minified ? '.min' : '') +
'.js',
library: 'Holidays',
libraryTarget: options.target[0]
},
resolve: {
// mainFields: ['browser', 'main', 'module']
},
optimization: {
minimize: options.minified
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}]
},
plugins
}
}
module.exports = createVariants(variants, createConfig)