-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
109 lines (107 loc) · 3.41 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
100
101
102
103
104
105
106
107
108
109
const path = require("path")
const webpack = require('webpack')
const HtmlWebpackPlugin = require("html-webpack-plugin")
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// const html = require('html-withimg-loader!./index.html');
module.exports = {
devtool: "eval-source-map", //生产阶段关闭这个选项
// devtool: false,
entry: {
app: "./src/index.js"
},
output: {
path: __dirname + "/dist",
filename: "js/common.js"
},
devServer: {
// host: '0.0.0.0',
port: 8080,
contentBase: './dist',
historyApiFallback: true, //不跳转
inline: true, //实时刷新
// hot:true,
},
plugins: [
new CleanWebpackPlugin(['dist']), //自动清理
new HtmlWebpackPlugin({
template: `${__dirname}/src/index.html`,
// template: __dirname+"/index.html",
inject: 'body', //script位置
hash: false, //每次生成不同哈希值
chunks: ['app']
}),
new webpack.optimize.OccurrenceOrderPlugin(), //分配id
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}), //压缩
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new ExtractTextPlugin("style.css"), //分离
// new HtmlWebpackPlugin.HotModuleReplacementPlugin(),//热加载插件
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
],
module: {
rules: [
{
test: /\.jsx$|\.js$/,
use:{
loader: 'eslint-loader',
},
enforce: "pre",
exclude: /bundle\.js$/,
include: `${__dirname}/src`,
},
{
test: /\.js$/,
use: {
loader: "babel-loader",
},
exclude: /node_modules/
},{
test: /\.css$/,
// use:[
// 'style-loader',
// { loader: 'css-loader', options: { importLoaders: 1 } },
// ]
loader: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [{
loader: 'css-loader',
options: {
minimize: true // css压缩
}
}],
})
},
{
test: /\.less$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: true
}
},
'less-loader'
]
},
{
test: /\.jpeg$/,
use: 'url-loader?limit=1024&name=[path][name].[ext]&outputPath=img/&publicPath=output/',
},
{
test: /\.(png|jpg|gif|woff|woff2)$/,
// loader: 'file-loader?name=img/[name].[ext]'
use:'file-loader?limit=1024&name=img/[name].[ext]'
}
]
}
}