-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
67 lines (62 loc) · 1.67 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
const TerserPlugin = require('terser-webpack-plugin');
const { readdirSync: readdir } = require('fs');
const webpack = require('webpack');
const { merge } = require('webpack-merge');
const isProduction = process.env.NODE_ENV === 'production';
const terser = new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true
}
});
const config = {
mode: process.env.NODE_ENV || 'none',
module: {
rules: [
{
test: /\.(png|jpg|gif)$/i,
use: [{ loader: 'url-loader', options: { limit: 8192 } }]
},
{
test: /\.ttf$/i,
use: [{ loader: 'url-loader' }]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [{ loader: 'babel-loader' }]
}
]
},
optimization: {
minimizer: isProduction ? [terser] : []
},
output: {
filename: '[name].js',
libraryTarget: 'commonjs',
path: `${__dirname}/plugins/.build`,
publicPath: '/'
},
externals: [
({ request }, done) =>
/^(\$:\/|gray-matter)/i.test(request)
? done(null, 'commonjs ' + request)
: done()
],
plugins: [new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })],
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js', '.json']
}
};
const targets = readdir('./plugins')
.filter(d => !d.startsWith('.'))
.map(plugin => require(`./plugins/${plugin}/webpack.config.js`))
.reduce((a, b) => a.concat(b), [])
.reduce((a, b) => ({ ...a, [b.target]: (a[b.target] || []).concat(b) }), {});
module.exports = Object.values(targets).map(plugins =>
merge(config, ...plugins)
);