This repository has been archived by the owner on Apr 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwebpack.config.js
59 lines (55 loc) · 1.52 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
const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const {BundleAnalyzerPlugin} = require("webpack-bundle-analyzer");
const package = require("./package.json");
module.exports = (env) => {
const IS_ANALYZE = env && env.analyze;
const common = {
entry: {
filename: path.resolve(__dirname, "./src/shogi.ts"),
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: "ts-loader",
options: {},
},
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
};
// For browsers
const BUNDLE_DIR = path.resolve(__dirname, "./bundle");
const bundle = merge(common, {
output: {
library: "ShogiJS",
filename: `shogi-${package.version}.min.js`,
path: BUNDLE_DIR,
clean: true,
},
optimization: {
minimize: true,
},
});
if (IS_ANALYZE) {
bundle.plugins = [new BundleAnalyzerPlugin()];
}
// For npm module
const DIST_DIR = path.resolve(__dirname, "./dist");
const dist = merge(common, {
output: {
libraryTarget: "commonjs2",
filename: "shogi.js",
path: DIST_DIR,
clean: true,
},
});
return [bundle, dist];
};