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 13
/
Copy pathwebpack.config.js
62 lines (59 loc) · 1.82 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
const path = require("path");
const webpack = require("webpack");
const {merge} = require("webpack-merge");
const {CleanWebpackPlugin} = require("clean-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const package = require("./package.json");
module.exports = (env) => {
const IS_ANALYZE = env && env.analyze;
const common = {
entry: {
filename: path.resolve(__dirname, "./src/main.ts"),
//filename: path.resolve(__dirname, './src/tst.js'),
//hoge: path.resolve(__dirname, './src/csa-parser.pegjs')
},
module: {
rules: [
{
test: /\.ts$/,
use: "ts-loader",
exclude: /node_modules/,
},
{
test: /\.pegjs$/,
use: "pegjs-loader",
},
],
},
resolve: {
extensions: [".ts", ".js", ".pegjs"],
},
};
// For browsers
const BUNDLE_DIR = path.resolve(__dirname, "./bundle");
const bundle = merge(common, {
output: {
library: "JSONKifuFormat",
filename: `json-kifu-format-${package.version}.min.js`,
path: BUNDLE_DIR,
},
plugins: [new CleanWebpackPlugin()],
optimization: {
minimize: true,
},
});
if (IS_ANALYZE) {
bundle.plugins.push(new BundleAnalyzerPlugin());
}
// For npm module
const DIST_DIR = path.resolve(__dirname, "./dist");
const dist = merge(common, {
output: {
libraryTarget: "commonjs2",
filename: "json-kifu-format.js",
path: DIST_DIR,
},
plugins: [new CleanWebpackPlugin()],
});
return [bundle, dist];
};