This repository has been archived by the owner on Apr 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
76 lines (70 loc) · 2.3 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
/* global __dirname, require, module */
// config for webpack 4
const webpack = require('webpack');
const path = require('path');
const env = require('yargs').argv.env;
const pkg = require('./package.json');
const TerserPlugin = require('terser-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const Var2EsmPlugin = require('webpack-var2esm-plugin');
let libraryName = 'my-module'; // pkg.name;
let libraryObjName = 'MyModule'; // name for ES module
let plugins = [], outputFile, minimize;
let isCompat = env.endsWith(':compat');
if (env.startsWith('min')) {
minimize = true;
outputFile = `${libraryName}${isCompat ? '.compat' : ''}.min.js`;
if (0) {
plugins.push(new BundleAnalyzerPlugin());
}
} else {
minimize = false;
outputFile = `${libraryName}${isCompat ? '.compat' : ''}.js`;
}
plugins.push(new Var2EsmPlugin(libraryObjName, outputFile, isCompat));
const target = 'var'; // libraryTarget MUST be 'var' for Var2EsmPlugin to work.
const config = {
entry: __dirname + '/src/index.js',
externals: { // https://webpack.js.org/configuration/externals/
},
output: {
path: __dirname + '/lib',
filename: outputFile,
library: libraryObjName,
libraryTarget: target,
libraryExport: 'default', // https://github.com/webpack/webpack/commit/de8fc51a6fe2aff3ea3a1c24d34d429897c3b694
umdNamedDefine: false // must be 'false' for m to be resolved in require([''], (m) => {});
},
optimization: {
minimize: minimize,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true
}
}
})
]
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/
},
{
test: /(\.jsx|\.js)$/,
loader: 'eslint-loader',
exclude: /node_modules/
}
]
},
resolve: {
modules: [path.resolve('./node_modules'), path.resolve('./src')],
extensions: ['.json', '.js']
},
plugins: plugins
};
module.exports = config;