-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
82 lines (82 loc) · 3.08 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
/*
作者:night
时间:2017-11-28
*/
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
// const CompressionPlugin = require("compression-webpack-plugin");
let dirJson = {
srcDir:__dirname+'/src/'
};
let getEntry = () =>{
var jsPath = path.resolve(dirJson.srcDir);/*先取到总的页面文件夹父级路径*/
var dirs = fs.readdirSync(jsPath);/*读取该路径下的所有文件夹对象*/
var files = {};
dirs.forEach((item) => {
if(item.indexOf(".js")==-1 && item.indexOf(".scss")==-1 && item.indexOf(".css")==-1){
files[item] = path.resolve(dirJson.srcDir, item+'/index.js');
}
});
return files;
}
let entrys = getEntry();
entrys.vendor = ['react'];
module.exports = {
entry: entrys,
output: {path: path.resolve(__dirname, './dist/'),filename: '[name]/[name].js',hotUpdateChunkFilename: './hot/hot-update.js',hotUpdateMainFilename: './hot/hot-update.json'},
devServer: {
port: 5678,compress:true,progress:true,host:"0.0.0.0",disableHostCheck:true,
contentBase:path.resolve(__dirname,"./"),
proxy:{
"/queryList":{target:"http://127.0.0.1:4567/queryList",pathRewrite:{'^/queryList':""},changeOrigin:true,secure:true}
}
},
watchOptions:{poll:1000,aggregeateTimeout:500,ignored:/node_modules/},
module: {
rules: [
{
test: /\.jsx|\.js$/,loader: 'babel-loader',exclude: /(node_modules|bower_components)/
},
{
test: /\.scss$/,
loaders: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{//CSS处理
test: /\.css$/,
loader: "style-loader!css-loader?modules",
exclude: /node_modules/,
},
{//antd样式处理
test:/\.css$/,
exclude:/src/,
use:[
{ loader: "style-loader"},
{
loader: "css-loader",
options:{
importLoaders:1
}
}
]
}
]
},
plugins: [
new ExtractTextPlugin('[name]/[name].css'),/*样式文件抽取并根据指定加载器编译*/
new UglifyJSPlugin(),/*css,js资源文件压缩*/
new webpack.HotModuleReplacementPlugin(),/*热更新*/
new webpack.optimize.ModuleConcatenationPlugin(),/*作用域提升,使代码体积更小*/
new webpack.optimize.CommonsChunkPlugin({name:'vendor',filename:'vendor.js'}),/*提取入口文件的第三方模块和公共模块*/
new webpack.ProvidePlugin({/*引入全局插件,jquery*/
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
]
};