-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
165 lines (156 loc) · 4.98 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
const { resolve } = require('path');
const merge = require('webpack-merge');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const moduleConf = require('./webpack-module.config');
const nomoduleConf = require('./webpack-nomodule.config');
const getHtmlOptions = require('./src/utils/html-webpack/get-html-options');
const pkg = require('./package.json');
const IS_DEV_SERVER = !!process.argv.find(arg => arg.includes('--mode=development'));
const { version } = pkg;
const copyStatics = {
copyPolyfills: [
{
from: resolve(__dirname, './node_modules/@webcomponents/webcomponentsjs/bundles/*.js'),
to: 'vendor/bundles/[name].' + version + '.[ext]'
},
{
from: resolve(__dirname, './node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js'),
to: 'vendor/custom-elements-es5-adapter.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/es5-shim/es5-shim.min.js'),
to: 'vendor/es5-shim.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/es5-shim/es5-sham.min.js'),
to: 'vendor/es5-sham.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/es6-shim/es6-shim.min.js'),
to: 'vendor/es6-shim.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/es6-shim/es6-sham.min.js'),
to: 'vendor/es6-sham.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/weakmap-polyfill/weakmap-polyfill.min.js'),
to: 'vendor/weakmap-polyfill.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/es6-promise/dist/es6-promise.min.js'),
to: 'vendor/es6-promise.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/intersection-observer/intersection-observer.js'),
to: 'vendor/intersection-observer.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/@webcomponents/shadycss/scoping-shim.min.js'),
to: 'vendor/scoping-shim.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/whatwg-fetch/fetch.js'),
to: 'vendor/fetch.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/object-fit-images/dist/ofi.min.js'),
to: 'vendor/ofi.' + version + '.js'
},
{
from: resolve(__dirname, './node_modules/raven-js/dist/raven.min.js'),
to: 'vendor/raven.' + version + '.js'
},
{
from: resolve(__dirname, './src/assets'),
to: 'assets'
}
]
};
if (IS_DEV_SERVER) {
copyStatics.copyPolyfills.push({
from: resolve(__dirname, './src/service-worker.js'),
to: 'service-worker.js'
});
}
const shared = env => {
const IS_MODULE_BUILD = env.BROWSERS === 'module';
const plugins = [
new HTMLWebpackPlugin(getHtmlOptions(IS_DEV_SERVER, IS_MODULE_BUILD, 'index')),
new HTMLWebpackPlugin(getHtmlOptions(IS_DEV_SERVER, IS_MODULE_BUILD, '404')),
new CopyWebpackPlugin(copyStatics.copyPolyfills)
];
return {
entry: {
'core': resolve(__dirname, 'src/index.js')
},
output: {
path: resolve(__dirname, 'public'),
chunkFilename: IS_MODULE_BUILD ? 'module.[chunkhash].fragment.' + version + '.js' : '[chunkhash].fragment.' + version + '.js',
filename: IS_MODULE_BUILD ? 'module.[name].' + version + '.js' : '[name].' + version + '.js',
publicPath: '/'
},
resolve: {
extensions: ['.js', '.styl']
},
module: {
rules: [
{
// If you see a file that ends in .html, send it to these loaders.
test: /\.html$/,
use: [
'text-loader'
]
},
{
test: /\.worker\.js$/,
use: [
{
loader: 'worker-loader',
options: {
name: IS_MODULE_BUILD ? 'module.[hash].worker.' + version + '.js' : '[hash].worker.' + version + '.js'
}
},
{
loader: 'babel-loader',
options: {
presets: [[
'env'
]],
plugins: [
'babel-plugin-syntax-dynamic-import',
['transform-runtime', {
'helpers': false,
'polyfill': false,
'regenerator': true
}],
['transform-object-rest-spread', {useBuiltIns: true}]
]
}
}
]
},
{
test: /\.styl$/,
use: [
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
sourceMap: true
}
},
{
loader: 'stylus-loader'
}
]
}
]
},
plugins
};
};
module.exports = (env = {}) => merge(env.BROWSERS === 'module' ? moduleConf(IS_DEV_SERVER) : nomoduleConf(IS_DEV_SERVER), shared(env));