-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
89 lines (86 loc) · 2.14 KB
/
webpack.config.js
File metadata and controls
89 lines (86 loc) · 2.14 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
// var ManifestPlugin = require('webpack-manifest-plugin');
const webpack = require('webpack');
module.exports = {
// entry: './src/index.js',
entry:{
app:'./src/index.ts',
print:'./src/print.js',
vendor: [
'lodash',
// 'react',
]
},
devtool: 'inline-source-map',
output: {
// filename: 'main.js',
filename:'[name].bundle.js',
chunkFilename:'[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
// mode:'production',
mode:'development',
// 热部署可以监听修改的页面 同时刷新浏览器
devServer: {
contentBase: './dist'
},
optimization:{
splitChunks:{
name: 'print'
}
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ]
},
plugins: [
// 可以将dist生成的文件清除避免缓存
new CleanWebpackPlugin(),
// 生成manifest文件,追踪文件打包路径
// new ManifestPlugin(),
// 这个可以把打包的js 自动引入到index.html入口文件里
new HtmlWebpackPlugin({
title: 'Webpack' // 主文件到标题
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'print' // 指定公共 bundle 的名称。
// }),
// new webpack.optimization.splitChunks({
// name:'vendor'
// })
// new webpack.optimize.CommonsChunkPlugin({
// name: 'vendor'
// }),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader'
]
}
]
}
};