-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
89 lines (83 loc) · 2.28 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
89
/**
* @file
*
* This file contains configuration to run the demo locally.
*/
const ProvidePlugin = require("webpack").ProvidePlugin;
const path = require("path");
const HTMLPlugin = require("html-webpack-plugin");
//const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
module.exports = (_, argv) => {
const mode = (argv || {}).mode || "development";
return {
entry: "./src/demo",
mode: mode,
devtool: mode === "development" ? "inline-source-map" : undefined,
module: {
rules: [
// source maps from typescript work
{ test: /\.js$/, loader: "source-map-loader", enforce: "pre" },
// load typescript outside of node_modules
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
options: {
compilerOptions: {
declaration: false
}
}
}
]
},
// load stylesheets -- only needed for development
{
test: /\.css$/,
loader: ["style-loader", "css-loader"]
},
// load png images -- only needed for development
{
test: /\.(png|jpg|gif)$/,
loader: "file-loader"
}
]
},
resolve: {
extensions: [".ts", ".js"]
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
devtoolModuleFilenameTemplate:
mode === "development" ? "[absolute-resource-path]" : undefined
},
optimization: {
splitChunks: {
chunks: "all",
minChunks: 1,
cacheGroups: {
// all other modules: enforce a module based on the folder
nodeModules: {
test: /\/node_modules\//,
enforce: true,
priority: -10,
name: function(mod) {
if (!mod.resource) return;
const modName = mod.resource.match(/\/node_modules\/([^\/]*)/);
return `modules-${modName[1]}`;
}
},
}
}
},
plugins: [
new HTMLPlugin({title: 'TGView'}),
// this is required by jstree -- and only jstree
new ProvidePlugin({
'jQuery': 'jquery'
})
]
};
};