-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
89 lines (88 loc) · 2.54 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
var path = require("path");
const { merge } = require("webpack-merge");
const devConf = require("./webpackConfig/dev");
const prodConf = require("./webpackConfig/prod");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
module.exports = (env) => {
return merge(
{
entry: "./src/entry.tsx",
output: {
path: path.resolve(__dirname, "build"),
filename: "[name].bundle.js",
},
resolve: {
extensions: [".ts", ".tsx", ".js"],
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: {
loader: "ts-loader",
options: {
allowTsInNodeModules: true,
},
},
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader",
options: { presets: ["@babel/env", "@babel/preset-react"] },
},
{
test: /\.(less|css)$/,
use: ["style-loader", "css-loader", "less-loader"],
},
{
test: /\.(jpg|png|gif)$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/images",
},
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, "public/sharedWorker"),
to: path.resolve(__dirname, "build/sharedWorker"),
},
{
from: path.resolve(__dirname, "public/serviceWorker"),
/*
如果将 serviceWorker.js脚本 放在 /serviceWorker 文件夹下
那么 service worker 支持的scope,也必须是 /serviceWorker 之下的
所以,要放在最外层,这样支持的最大scope就是根了 /
综述:service worker 的 max scope 是它所在的目录位置
*/
to: path.resolve(__dirname, "build"),
},
],
}),
],
// optimization: {
// splitChunks: {
// chunks: "all",
// cacheGroups: {
// vendors: {
// test: /[\\/]node_modules[\\/]/,
// name: "vendors",
// },
// },
// },
// },
},
env.development ? devConf() : prodConf()
);
};