-
Notifications
You must be signed in to change notification settings - Fork 63
/
webpack.config.js
119 lines (111 loc) · 2.65 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
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = (env, options) => {
const mode = options.mode || 'development';
const config = {
mode,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.(png|jp(e*)g|svg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[hash]-[name].[ext]',
},
},
],
},
],
},
devtool: 'source-map',
};
if ('production' === mode) {
var minimizer = !env.build
? new TerserPlugin({
terserOptions: {},
minify: (file) => {
const uglifyJsOptions = {
sourceMap: true,
};
return require('uglify-js').minify(file, uglifyJsOptions);
},
})
: new TerserPlugin({
terserOptions: {},
minify: (file) => {
const uglifyJsOptions = {
sourceMap: false,
};
return require('uglify-js').minify(file, uglifyJsOptions);
},
});
config.devtool = false;
config.optimization = {
// minimize: true,
// minimizer: [minimizer, new CssMinimizerPlugin()],
minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: true,
},
// sourceMap: true,
}),
new CssMinimizerPlugin(),
],
};
}
var react_blueprints = [
{
dest_path: './assets/js',
src_files: {
'tutor-front.min': './assets/react/front/tutor-front.js',
'tutor-admin.min': './assets/react/admin-dashboard/tutor-admin.js',
'tutor-course-builder.min': './assets/react/course-builder/index.js',
'tutor-setup.min': './assets/react/admin-dashboard/tutor-setup.js',
'tutor.min': './assets/react/v2/common.js',
'tutor-gutenberg.min': './assets/react/gutenberg/index.js',
},
},
{
dest_path: './v2-library/bundle',
src_files: {
'main.min': './v2-library/_src/js/main.js',
},
},
{
dest_path: './.docz/static/v2-library/bundle',
src_files: {
'main.min': './v2-library/_src/js/main.js',
},
},
];
var configEditors = [];
for (let i = 0; i < react_blueprints.length; i++) {
let { src_files, dest_path } = react_blueprints[i];
configEditors.push(
Object.assign({}, config, {
name: 'configEditor',
entry: src_files,
output: {
path: path.resolve(dest_path),
filename: `[name].js`,
},
}),
);
}
return [...configEditors];
};