-
Notifications
You must be signed in to change notification settings - Fork 17
/
webpack.config.js
88 lines (77 loc) · 2.79 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
const webpack = require('webpack');
const path = require('path');
const ROOT_PATH = path.resolve(__dirname);
const MODULES_PATH = path.join(ROOT_PATH, './node_modules'); // node包目录
const BUILD_PATH = path.join(ROOT_PATH, './dist'); // 最后打包目录
//分离CSS插件
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const CleanPlugin = require('clean-webpack-plugin');//cnpm install clean-webpack-plugin --save-dev
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin
const precss = require('precss');
const autoprefixer = require('autoprefixer');
var alias = {
'jquery':__dirname+'/lib/jquery-1.10.2',//jq
'jquery-cookie':__dirname+'/lib/jquery.cookie',//jq-cookie
'jquery-lazyload':__dirname+'/lib/jquery.lazyload',//jq-图片懒加载
'jquery-qrcode':__dirname+'/lib/jquery.qrcode',//jq-生成二维码
};
module.exports = {
devtool: 'eval-source-map',
entry: {
index: './src/App.js',
common: ["react","react-dom","jquery","underscore"],
},
output: {
path: path.resolve(__dirname, './dist/js'),
publicPath: '',
filename: '[name].js', // 输出文件名
},
module: {
//加载器配置
loaders: [
{
test: /(\.css|\.scss|\.sass)$/,
loader: ExtractTextPlugin.extract("style-loader","css-loader?modules!sass-loader")
},
{test: /\.(png|jpg)$/, loader: 'url-loader?limit=1&name=../images/[name].[ext]'},
{test: /\.jsx?$/,loader: ['babel-loader'],query: {presets: ['es2015','react']}}
]
} ,
postcss: function () {
return [precss, autoprefixer];
},
resolve:{
//查找module的话从这里开始查找
//自动扩展文件后缀名,意味着我们require模块可以省略不写后缀名
extensions: ['','.css','.scss','.js'],
//模块别名定义,方便后续直接引用别名,无须多写长长的地址
alias:alias
},
plugins: [
// new webpack.HotModuleReplacementPlugin(),//热加载
// 把jquery作为全局变量插入到所有的代码中
// 然后就可以直接在页面中使用jQuery了
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
/* new webpack.optimize.CommonsChunkPlugin('common.js'),
new webpack.optimize.CommonsChunkPlugin({
// 与 entry 对应
name: 'common',
// 输出的公共资源名称
filename: 'common.js',
// 对所有entry实行这个规则
minChunks: Infinity
}),
*/
new ExtractTextPlugin("../css/[name].css"),
new CleanPlugin(['dist'], {
"root": ROOT_PATH,
verbose: true,
dry: false,
exclude: ['index.html']
}),
],
};