-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.js
75 lines (73 loc) · 2.09 KB
/
webpack.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
const path = require("path");
const webpack = require("webpack");
const { WebpackManifestPlugin } = require("webpack-manifest-plugin");
const glob = require("glob");
const BundleAnalyzerPlugin =
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const process = require("global/process");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const ANALYZE = false;
const PROD = process.env.NODE_ENV === "production";
const OUTPUT_DIR = "dist/";
module.exports = {
mode: PROD ? "production" : "development",
entry: glob.sync("./src/client/javascripts/*.ts*").reduce(
(entries, entry) =>
Object.assign(entries, {
[entry
.replace("./src/client/javascripts/", "")
.replace(/(\.ts|\.tsx)$/, "")]: entry,
}),
{}
),
output: {
filename: PROD ? "[name]-[chunkhash].js" : "[name].js",
path: path.resolve(__dirname, OUTPUT_DIR),
publicPath: "",
},
...(PROD ? {} : { devtool: "source-map" }),
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
},
},
],
},
],
},
resolve: {
plugins: [new TsconfigPathsPlugin({ configFile: "tsconfig.json" })],
// options for resolving module requests
// (does not apply to resolving to loaders)
modules: ["node_modules", path.resolve(__dirname, "src")],
mainFields: ["browser", "main", "module"],
// directories where to look for modules
extensions: [".js", ".json", ".jsx", ".ts", ".tsx"],
// extensions that are used
alias: {},
/* Alternative alias syntax (click to show) */
/* Advanced resolve configuration (click to show) */
},
plugins: [
new WebpackManifestPlugin({
basePath: "/",
fileName: "asset-manifest.json",
}),
...(ANALYZE ? [new BundleAnalyzerPlugin()] : []),
...(PROD
? [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production"),
},
}),
]
: []),
],
};