-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (90 loc) · 2.4 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
const path = require('path');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = (env, argv) => ({
entry:{
move: './src/move.js',
},
output: {
path: path.resolve(__dirname, './dist'),
publicPath: argv.mode === 'production' ? "http://ossmuxi-h5.muxixyz.com/2019spring/" : "/",
filename: 'js/[name].js'
},
module:{
rules:[
{
test: /\.css$/,
// use: ["style-loader", "css-loader"],
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader",
// publicPath: "../"
})
},
{
test: /\.(mp(3|4))$/,
use: {
loader: 'file-loader',
options: {
name: 'media/[name].[ext]',
}
}
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
use:[
{
loader: 'url-loader',
options: {
limit: 1024,
name: 'img/[name].[ext]',
// publicPath: "http://ossmuxi-h5.muxixyz.com/2019spring/"
}
}
]
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
options: {
minimize: true,
attrs: ['img:src', 'audio:src', 'video:src'],
}
}
}
]
},
plugins:[
//独立打包css
new ExtractTextPlugin('css/[name].css'),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }],
},
canPrint: true
}),
//对html模板进行处理,生成对应的html,引入需要的资源模块
new HtmlWebpackPlugin({
template:'./move.html',//模板文件
filename:'index.html',//目标文件
inject:true,//资源加入到底部
hash:false,//加入版本号
// chunks:['move'],
}),
],
//本地服务器配置
devServer: {
contentBase: "./",//本地服务器所加载的页面所在的目录
historyApiFallback: true,//不跳转
inline: true, //实时刷新
open: true //是否运行成功后直接打开页面
},
//不显示警告
performance: {
hints: false
}
})