This repository has been archived by the owner on Sep 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
76 lines (69 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
68
69
70
71
72
73
74
75
76
/* eslint strict: off, node/no-unsupported-features: ["error", { version: 6 }] */
"use strict"
const fs = require("fs-extra")
const path = require("path")
const webpack = require("webpack")
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer")
const { EnvironmentPlugin } = webpack
const OptimizeJsPlugin = require("optimize-js-plugin")
const TerserPlugin = require("terser-webpack-plugin")
const UnusedPlugin = require("unused-webpack-plugin")
const isProd = /production/.test(process.env.NODE_ENV)
const terserOptions = fs.readJSONSync("./.terserrc")
/* eslint-disable sort-keys */
const config = {
devtool: false,
entry: {
"create-esm": "./src/create-esm.js"
},
output: {
filename: "[name].js",
libraryExport: "default",
libraryTarget: "commonjs2",
path: path.resolve("build"),
pathinfo: false
},
mode: isProd ? "production" : "development",
module: {
rules: [
{
loader: "babel-loader",
test: /\.js$/,
type: "javascript/auto"
}
]
},
node: false,
optimization: {
minimizer: [
new TerserPlugin({ terserOptions })
],
nodeEnv: false
},
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: "static",
defaultSizes: "gzip",
logLevel: "silent",
openAnalyzer: false,
reportFilename: "report.html"
}),
new UnusedPlugin({
directories : [path.resolve("src")],
exclude: [
".*",
"*.json"
],
root : __dirname
})
],
target: "node"
}
/* eslint-enable sort-keys */
if (isProd) {
config.plugins.push(
new OptimizeJsPlugin,
new EnvironmentPlugin({ NODE_DEBUG: false })
)
}
module.exports = config