forked from GrapesJS/mjml
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
61 lines (59 loc) · 1.54 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
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const fs = require('fs');
const pkg = require('./package.json');
const name = pkg.name;
let plugins = [];
module.exports = (env, options) => {
const isProd = (options.mode === 'production');
if (!isProd) {
const index = 'index.html';
const indexDev = `_${index}`;
const template = fs.existsSync(indexDev) ? indexDev : index;
plugins.push(new HtmlWebpackPlugin({ template }));
}
return {
entry: './src',
mode: isProd ? 'production' : 'development',
output: {
path: path.join(__dirname),
filename: `dist/${name}.min.js`,
library: name,
libraryExport: 'default',
libraryTarget: 'umd',
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
resolve: {
alias: {
'fs': path.resolve(__dirname, 'mocks/fs'),
'uglify-js': path.resolve(__dirname, 'mocks/uglify-js'),
}
},
// make sure to keep_fnames or else it will break grapesjs, see https://github.com/artf/grapesjs-mjml/issues/110
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_fnames: true
},
}),
],
},
target: 'web',
plugins: plugins
};
};