-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwebpack.config.js
113 lines (110 loc) · 2.92 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
113
const path = require("path");
const webpack = require("webpack");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MarkoPlugin = require("@marko/webpack/plugin").default;
const CSSExtractPlugin = require("mini-css-extract-plugin");
const SpawnServerPlugin = require("spawn-server-webpack-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const { NODE_ENV } = process.env;
const isProd = NODE_ENV === "production";
const isDev = !isProd;
const markoPlugin = new MarkoPlugin();
const spawnedServer = isDev && new SpawnServerPlugin();
module.exports = [
compiler({
name: "Client",
optimization: {
splitChunks: {
chunks: "all",
maxInitialRequests: 3
}
},
output: {
filename: "[name].[contenthash:8].js",
path: path.join(__dirname, "dist/client")
},
devServer: isDev ? {
overlay: true,
stats: "minimal",
contentBase: false,
...spawnedServer.devServerConfig
}: undefined,
plugins: [
new webpack.DefinePlugin({
"process.browser": true
}),
new CSSExtractPlugin({
filename: "[name].[contenthash:8].css"
}),
isProd && new OptimizeCssAssetsPlugin(),
markoPlugin.browser
]
}),
compiler({
name: "Server",
target: "async-node",
externals: [/^[^./!]/], // excludes node_modules
optimization: {
minimize: false
},
output: {
libraryTarget: "commonjs2",
path: path.join(__dirname, "dist/server")
},
plugins: [
new webpack.DefinePlugin({
"process.browser": undefined,
"process.env.BUNDLE": true
}),
new webpack.BannerPlugin({
banner: 'require("source-map-support").install();',
raw: true
}),
new CSSExtractPlugin({
filename: "[name].[contenthash:8].css"
}),
isDev && spawnedServer,
markoPlugin.server
]
})
];
// Shared config for both server and client compilers.
function compiler(config) {
return {
...config,
mode: isProd ? "production" : "development",
devtool: isProd ? "source-map" : "inline-source-map",
output: {
publicPath: "/static/",
...config.output
},
resolve: {
extensions: [".js", ".json", ".marko"]
},
module: {
rules: [
{
test: /\.marko$/,
loader: "@marko/webpack/loader"
},
{
test: /\.(less|css)$/,
use: [CSSExtractPlugin.loader, "css-loader", "less-loader"]
},
{
test: /\.svg/,
loader: "svg-url-loader"
},
{
test: /\.(jpg|jpeg|gif|png)$/,
loader: "file-loader",
options: {
// File assets from server & browser compiler output to client folder.
outputPath: "../client"
}
}
]
},
plugins: [...config.plugins, isProd && new CleanWebpackPlugin()].filter(Boolean)
};
}