forked from vstconsulting/polemarch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
112 lines (104 loc) · 2.41 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const VueLoaderPlugin = require("vue-loader/lib/plugin");
require("dotenv").config();
const ENV = process.env.APP_ENV;
const isProd = ENV === "prod";
const enableAnalyzer = process.env.BUNDLE_ANALYZER === "true";
const KB = 1024;
const entrypoints_dir = __dirname + "/frontend_src";
function setMode() {
if (isProd) {
return "production";
} else {
return "development";
}
}
const config = {
mode: setMode(),
entry: {
pmlib: entrypoints_dir + "/main.js",
pmTests: entrypoints_dir + "/tests/index.js"
},
output: {
path: __dirname + "/polemarch/static/polemarch",
filename: "[name].js",
chunkFilename: "[name].chunk.js",
publicPath: "/static/polemarch/",
library: "[name]",
libraryTarget: "window"
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new CleanWebpackPlugin(),
new VueLoaderPlugin()
],
externals: {
moment: 'moment',
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
presets: [
[
"@babel/preset-env",
{
corejs: 3,
useBuiltIns: "usage"
}
]
]
}
},
exclude: [/node_modules/]
},
{
test: /\.((css)|(scss))$/i,
use: ["style-loader", "css-loader", "sass-loader"]
},
{
test: /.woff2$/,
use: {
loader: "url-loader",
options: {
limit: 100 * KB
}
}
},
{
test: /.(png|jpg|jpeg|gif|svg|woff|ttf|eot)$/,
use: {
loader: "url-loader",
options: {
limit: 10 * KB
}
}
},
{
test: /\.vue$/,
loader: "vue-loader"
}
]
},
optimization: {
chunkIds: "natural",
minimize: true,
minimizer: [
new TerserPlugin({
parallel: true
}),
new OptimizeCSSAssetsPlugin()
]
}
};
if (enableAnalyzer) {
config.plugins.push(new BundleAnalyzerPlugin());
}
module.exports = config;