-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
112 lines (111 loc) · 4.47 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 Webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = [
{
// entry為入口,webpack從這裏開始編譯
entry: ['babel-polyfill', Path.join(__dirname, './src/scripts/main.js')],
// output為輸出 path代表路徑 filename代表文檔名稱
output: {
publicPath: './',
path: Path.join(__dirname, './bundle'),
filename: 'scripts/bundle.[hash:8].js',
chunkFilename: 'scripts/[name].[chunkhash:8].js',
},
// module是配置所有模塊要經過什麼處理
// test:處理什麼類型的文檔,use:用什麼,include:處理這裏的,exclude:不處理這裏的
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
include: Path.join(__dirname, 'src'),
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 8192, // 8k一下的轉義為base64
name: '[name].[ext]',
outputPath: 'assets/images/',
publicPath: '../images/',
},
},
],
},
],
},
mode: 'production',
plugins: [
new CleanWebpackPlugin(['bundle']),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'assets/styles/[name].[hash:8].min.css',
chunkFilename: 'assets/styles/[id].[hash:8].min.css',
}),
new HtmlWebpackPlugin({
filename: 'index.html', // 打包後的文檔名
template: Path.join(__dirname, './src/index.html'), // 要打包文檔的路徑
}),
new CopyWebpackPlugin([{ from: './src/assets/images/', to: './assets/images/' }]),
new Webpack.DefinePlugin({
CANVAS_RENDERER: JSON.stringify(true),
WEBGL_RENDERER: JSON.stringify(true),
}),
],
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'common',
chunks: 'all',
},
},
},
minimizer: [new OptimizeCSSAssetsPlugin({})],
},
},
{
// entry為入口,webpack從這裏開始編譯
entry: ['babel-polyfill', Path.join(__dirname, './src/scripts/main.js')],
// output為輸出 path代表路徑 filename代表文檔名稱
output: {
publicPath: './',
path: Path.join(__dirname, './bundle'),
// filename: 'scripts/bundle.[hash:8].js',
// chunkFilename: 'scripts/[name].[chunkhash:8].js',
},
// module是配置所有模塊要經過什麼處理
// test:處理什麼類型的文檔,use:用什麼,include:處理這裏的,exclude:不處理這裏的
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
},
],
},
mode: 'production',
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'assets/styles/[name].[hash:8].css',
chunkFilename: 'assets/styles/[id].[hash:8].css',
}),
],
},
];