-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
112 lines (103 loc) · 2.33 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 path = require("path");
const { merge } = require("webpack-merge");
const webpack = require("webpack");
const { MiniHtmlWebpackPlugin } = require("mini-html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
const pkg = require("./package.json");
const PATHS = {
app: path.join(__dirname, "app"),
build: path.join(__dirname, "build"),
style: path.join(__dirname, "app/main.css"),
searchIndex: path.join(__dirname, "app/search_index.json"),
};
const common = {
entry: {
app: PATHS.app,
style: PATHS.style,
},
resolve: {
extensions: [".js", ".jsx"],
},
output: {
path: PATHS.build,
filename: "[name].js",
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: "babel-loader",
include: PATHS.app,
},
],
},
plugins: [
new MiniHtmlWebpackPlugin({
title: "Lunr demo",
}),
],
};
const dev = merge(common, {
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
// display only errors to reduce the amount of output
stats: "errors-only",
// parse host and port from env so this is easy
// to customize
host: process.env.HOST,
port: process.env.PORT,
},
module: {
rules: [
// Define development specific CSS setup
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
include: PATHS.app,
},
],
},
performance: {
hints: false,
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
],
});
const build = {
entry: {
vendor: Object.keys(pkg.dependencies),
},
output: {
path: PATHS.build,
filename: "[name].[chunkhash].js",
chunkFilename: "[chunkhash].js",
},
module: {
rules: [
// Extract CSS during build
{
test: /\.css$/,
loader: [MiniCssExtractPlugin.loader, "css-loader"],
include: PATHS.app,
},
],
},
optimization: {
splitChunks: {
chunks: "all",
},
},
plugins: [new CleanWebpackPlugin(), new MiniCssExtractPlugin()],
};
module.exports = (env) => {
if (env === "build") {
return merge(common, build);
}
return merge(common, dev);
};