-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
webpack.config.js
112 lines (107 loc) · 2.7 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
'use strict';
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const TerserPlugin = require("terser-webpack-plugin");
function webpackConfig(target, mode) {
let filename;
if (target === 'var') {
filename = `painterro-${require('./package.json').version}.min.js`
} else if (target === 'var-latest') {
filename = 'painterro.min.js';
target = 'var';
} else {
filename = `painterro.${target}.js`;
}
let options = {
mode,
entry: ['./js/main.js'],
output: {
path: path.resolve(__dirname, 'build'),
filename,
libraryTarget: target,
},
module: {
rules: [
{
enforce: "pre",
test: /\.js$/,
exclude: /node_modules/,
loader: "eslint-loader",
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
},
{
test: /\.(ttf|woff|woff2|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: "url-loader"
}
]
},
stats: {
colors: true
},
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
}
if (target === 'var') {
options.output.library = 'Painterro';
options.output.libraryExport = 'default';
options.target = 'browserslist';
options.module.rules.push({
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
// sourceType: "module",
presets: [["@babel/preset-env", {
"modules": "commonjs",
"useBuiltIns": "entry",
"corejs": "2"
}]],
}
});
} else {
options.target = 'es2020';
}
if (mode === 'development') {
options = {
...options,
devServer: {
injectClient: false,
static: path.join(__dirname, 'build'),
hot: true,
},
devtool: 'inline-source-map',
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: `report-${target}.html`,
openAnalyzer: false,
}),
],
}
}
return options;
}
const isDevServer = process.argv.find(v => v.includes('serve'));
if (!isDevServer) {
console.log('Building production');
module.exports = [
webpackConfig('var', 'production'),
webpackConfig('var-latest', 'production'),
webpackConfig('commonjs2', 'production'),
webpackConfig('amd', 'production'),
webpackConfig('umd', 'production')
];
} else {
console.log('Building development');
module.exports = [webpackConfig('var-latest', 'development')];
}