-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.base.js
More file actions
65 lines (62 loc) · 1.79 KB
/
Copy pathwebpack.base.js
File metadata and controls
65 lines (62 loc) · 1.79 KB
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
const path = require("path");
const webpack = require("webpack");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const AddAssetHtmlPlugin = require("add-asset-html-webpack-plugin");
const HappyPack = require("happypack");
const os = require("os");
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
module.exports = {
output: {
path: path.resolve(__dirname, "./dist"),
filename: "[name].[hash:8].js",
chunkFilename: "[name].[hash:8].js",
},
module: {
rules: [
{
test: /\.js$/,
use: ["happypack/loader?id=happyBabel"],
include: path.resolve(__dirname, "./src"),
exclude: path.resolve(__dirname, "./node_modules"),
},
{
test: /\.(gif|jpg|jpeg|png)$/,
loader: "url-loader",
options: {
name: "[name].[ext]?[hash:8]",
limit: 8192,
},
},
],
},
plugins: [
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, "./public"),
to: path.resolve(__dirname, "./dist"),
},
]),
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new AddAssetHtmlPlugin({
filepath: path.resolve(__dirname, "./dll/*.dll.js"),
}),
new webpack.DllReferencePlugin({
manifest: path.resolve(__dirname, "./dll/vendors.manifest.json"),
}),
new HappyPack({
id: "happyBabel",
loaders: ["cache-loader", "babel-loader?cacheDirectory=true"],
threadPool: happyThreadPool,
verbose: true,
}),
new CleanWebpackPlugin(), // 生成前先清除dist目录
],
resolve: {
modules: [path.resolve(__dirname, "node_modules")],
extensions: [".jsx", ".js"],
},
};