-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.dev.js
76 lines (75 loc) · 2.59 KB
/
webpack.config.dev.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
const Path = require('path');
const Webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-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: {
path: Path.join(__dirname, './bundle'),
filename: 'bundle.[hash:8].js',
chunkFilename: '[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
},
},
],
},
],
},
mode: 'development',
plugins: [
new CleanWebpackPlugin(['bundle']),
new MiniCssExtractPlugin({
filename: 'main.[hash:8].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',
},
},
},
},
devServer: {
contentBase: Path.join(__dirname, './bundle'), // 啟動路徑
host: '10.10.0.10', // 域名
port: 8081, // 端口號
},
};