-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
181 lines (176 loc) · 5.07 KB
/
webpack.common.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
const path = require('path')
const webpack = require('webpack')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
// happypack
const HappyPack = require('happypack')
const {
osCpusLength,
commonInclude,
commonExclude,
// devServer 用這個
devServerPort,
// expressDevServer 用這個
expressDevServerPort
} = require('./webpack.define.js')
// console.log(`aaaaaaaaaaaaaaaaaa: ${process.env.NODE_ENV}`)
module.exports = {
entry: {
index: './ClientApp/js/index.js',
index2: './ClientApp/js/index2.js'
// index3: './ClientApp/js/index.ts'
},
output: {
publicPath: '/',
path: path.resolve(__dirname, 'wwwroot/webpackTest'),
chunkFilename: '[name].bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
include: [commonInclude],
exclude: [commonExclude],
use: {
loader: 'happypack/loader?id=babelJs'
// options: {
// presets: ['@babel/preset-env']
// }
}
},
// 注意2:虽然html-webpack-plugin会默认解析ejs语法,但我测试的时候无法解析导入的侧栏、头部、底部的模板
{
test: /\.ejs$/,
use: 'ejs-compiled-loader'
},
{
// 使用 ts-loader 时,设置 happyPackMode: true / transpileOnly: true
test: /\.tsx?$/,
include: [commonInclude],
exclude: [commonExclude],
use: ['ts-loader']
},
{
test: /\.(png|svg|jpg|gif)$/,
include: [commonInclude],
exclude: [commonExclude],
use: ['file-loader']
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
include: [commonInclude],
exclude: [commonExclude],
use: ['file-loader']
},
{
test: /\.(csv|tsv)$/,
include: [commonInclude],
exclude: [commonExclude],
use: ['csv-loader']
},
{
test: /\.xml$/,
include: [commonInclude],
exclude: [commonExclude],
use: ['xml-loader']
}
]
},
plugins: [
new CleanWebpackPlugin(['wwwroot/webpackTest']),
new HappyPack({
id: 'babelJs',
threadPool: HappyPack.ThreadPool({ size: osCpusLength }),
loaders: [
{
loader: 'babel-loader',
query: {
// optional: 'runtime',
cacheDirectory: true
}
// options: {
// presets: ['@babel/preset-env']
// }
}
]
}),
// new HtmlWebpackPlugin({
// inject: false,
// template: path.resolve(__dirname, 'ClientApp/indexTemplate.html'),
// filename: path.resolve(__dirname, 'index.html'),
// chunks: ['index'],
// // 跳過那些模塊
// // excludeChunks: [],
// HtmlWebpackPluginOverride: true,
// // hash:true,//防止缓存
// outputFile: {
// vendor: 'wwwroot/vendor/dll.vendor.js',
// isProd: false,
// port: devServerPort
// },
// minify: true,
// // 啟用手動排序
// chunksSortMode: 'manual',
// // 跟著HtmlWebpackHarddiskPlugin套件
// alwaysWriteToDisk: true
// }),
// new HtmlWebpackPlugin({
// template: path.resolve(__dirname, 'ClientApp/ejs/index_2/index_2.ejs'),
// filename: path.resolve(__dirname, 'index_2.html'),
// chunks: ['index'],
// HtmlWebpackPluginOverride: true,
// // hash:true,//防止缓存
// outputFile: {
// vendor: 'wwwroot/vendor/dll.vendor.js',
// isProd: false,
// port: devServerPort
// },
// minify: true,
// // 啟用手動排序
// chunksSortMode: 'manual',
// // 跟著HtmlWebpackHarddiskPlugin套件
// alwaysWriteToDisk: true
// }),
// //強制"HtmlWebpackPlugin"進行編譯成實體檔案
// new HtmlWebpackHarddiskPlugin(),
new webpack.DllReferencePlugin({
manifest: require('./wwwroot/vendor/vendor.manifest.json')
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, `ClientApp/cpoyVendor/aa/testa.js`),
to: path.resolve(__dirname, `wwwroot/cpoyVendor`),
toType: 'dir'
},
{
from: path.resolve(__dirname, `ClientApp/cpoyVendor/bb/testb.js`),
to: path.resolve(__dirname, `wwwroot/cpoyVendor`),
toType: 'dir'
},
{
from: path.resolve(__dirname, `ClientApp/cpoyVendor/`),
to: path.resolve(__dirname, `wwwroot/cpoyVendor/cpoyVendorTwo`),
toType: 'dir'
},
{
from: path.resolve(__dirname, `ClientApp/cpoyVendor/credit`),
to: path.resolve(__dirname, `wwwroot/cpoyVendor/credit`),
toType: 'dir'
},
{
from: path.resolve(__dirname, `ClientApp/images`),
to: path.resolve(__dirname, `wwwroot/images`),
toType: 'dir'
},
])
// new webpack.ProvidePlugin({
// _: 'lodash' //所有页面都会引入 _ 这个变量,不用再import引入
// $: "jquery",
// jQuery: "jquery"
// })
],
stats: {
// `webpack --colors` 等同于
colors: true
}
}