-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
104 lines (101 loc) · 2.26 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
/**
* Webpack config for building project
* https://webpack.js.org/
*/
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const _ = require('lodash');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// For whatever reason babel doesn't seem to work with the Svelte
// loaders unless the config is here
const browsersList = path.join(process.cwd(), 'browserslist');
let browserTargets;
if (fs.existsSync(browsersList)) {
browserTargets = fs
.readFileSync(browsersList, 'utf-8')
.split('\n')
.filter(l => {
return l && l[0] !== '#' && l[0] !== '/';
})
.join(', ');
}
// Loader configs
const loaders = {
svelte: {
loader: 'svelte-loader',
options: {
hydratable: true,
store: true
}
},
babel: {
loader: 'babel-loader',
options: {
cacheDirectory:
process.env.NODE_ENV === 'development' || process.env.DEBUG
? false
: true,
presets: [
[
'@babel/preset-env',
{
debug:
process.env.NODE_ENV === 'development' || process.env.DEBUG
? true
: false,
targets: {
browsers: browserTargets ? browserTargets : 'ie >= 10'
}
}
]
],
plugins: ['lodash']
}
}
};
module.exports = {
mode:
~['development', 'production', 'none'].indexOf(process.env.NODE_ENV) ||
'production',
devtool: 'source-map',
performance: {
maxAssetSize: 1250000,
maxEntrypointSize: 1250000
},
// Needs a key so that [name] can be used in output.
entry: _.mapKeys(glob.sync('./app/*.js'), v => {
return path.basename(v, '.js');
}),
output: {
path: path.resolve(__dirname, './build/js'),
filename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.(js)$/,
use: [loaders.babel]
},
{
test: /\.(svelte\.html|svelte)$/,
use: [loaders.babel, loaders.svelte]
}
]
},
optimization: {
minimizer: [
new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
ecma: 5,
compress: true,
safari10: true,
mangle: {
safari10: true
}
}
})
]
}
};