-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
88 lines (85 loc) · 1.96 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
const path = require("path");
const ESLintPlugin = require("eslint-webpack-plugin");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const CircularDependencyPlugin = require("circular-dependency-plugin");
const TerserPlugin = require("terser-webpack-plugin");
module.exports = (env, argv) => {
const isDev = argv.mode === "development";
const plugins = [];
if (!isDev) {
plugins.push(
...[
new ESLintPlugin({
emitWarning: true,
emitError: true,
failOnError: true,
failOnWarning: true,
extensions: ["ts", "tsx", "js", "jsx", "json"],
}),
new ForkTsCheckerWebpackPlugin({
formatter: "codeframe",
}),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
cwd: process.cwd(),
}),
]
);
}
return {
mode: "production",
target: "web",
entry: ["./src/index.ts"],
output: {
filename: "index.js",
path: __dirname + "/dist",
library: "use-mounted-effect",
libraryTarget: "umd",
globalObject: "this",
umdNamedDefine: true,
},
resolve: {
extensions: [".ts"],
alias: {
react: path.resolve(__dirname, "./node_modules/react"),
},
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: [/node_modules/],
use: [
{
loader: "babel-loader",
},
],
},
],
},
externals: {
react: {
commonjs: "react",
commonjs2: "react",
amd: "React",
root: "React",
},
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: !isDev,
},
output: {
comments: false,
},
},
}),
],
},
plugins,
};
};