-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
122 lines (120 loc) · 3.11 KB
/
Copy pathwebpack.config.js
File metadata and controls
122 lines (120 loc) · 3.11 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
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
113
114
115
116
117
118
119
120
121
122
//套件加載
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
//設定CleanWebpackPlugin參數
let cleanFolderInit = {
//清除目錄名稱
target: [
'build',
'dist'
],
//配置選項
options: {
root: path.resolve('./'),
verbose: true
// exclude: ['*.html']
}
}
module.exports = {
// Webpack模式,目前設定為development
mode: 'development',
// 流程入口位置
entry: {
main: './resources/global/entry.js'
},
// 輸出位置,filename定義輸出的js檔名
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'js/bundle.js'
},
module: {
//設定每個Loader配置
rules: [
{
//Eslint-Loader
enforce: 'pre',
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'eslint-loader',
options: {
emitError: true
}
},
{
//Babel-Loader
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: [require('@babel/plugin-proposal-object-rest-spread')]
}
}
},
{
// Sass-loader + css-loader
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
}
]
},
//設定每個Plugins配置
plugins: [
//每次webpack bundle前先行移除資料夾
new CleanWebpackPlugin(
cleanFolderInit.target,
cleanFolderInit.options
),
//每次webpack bundle前先行複製or移動資料夾
new CopyWebpackPlugin([
{
from: './resources/global/images/',
to: './images/',
//是否強制覆蓋
force: true
}
]),
//打包Sass檔案,並透過Sass / Css loader最後輸出成css檔
new MiniCssExtractPlugin({
filename: '/css/[name].css',
chunkFilename: '[id].css'
}),
//自動加載css / js檔案並重新建置html檔案
new HtmlWebpackPlugin({
chunks: ['main'],
filename: 'index.html',
// template: path.resolve(__dirname, `../resource/${env.lang}/${env.name}/${env.name}.pug`),
template: path.resolve(__dirname, './resources/global/index.html'),
// data: require(`../resource/${env.lang}/${env.name}/${env.name}.json`),
inject: true
})
],
//localHost server配置
devServer: {
//顯示警告or錯誤訊息
overlay: {
warnings: true,
errors: true
},
//每次bundle結束後自動開啟頁面
open: true,
//開啟的頁面名稱
openPage: 'index.html',
compress: true,
//是否持續監聽指定目錄下所有檔案異動
watchContentBase: true,
//監聽指定目錄名稱
contentBase: path.join(__dirname, './resources/global/'),
//填入正確IP位置
// host: '192.168.1.123',
port: 3000
}
}