-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.production.js
117 lines (112 loc) · 3.77 KB
/
webpack.production.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
110
111
112
113
114
115
116
117
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var webpack = require('webpack')
var path = require('path')
var AssetsPlugin = require('assets-webpack-plugin');
var assetsPluginInstance = new AssetsPlugin({filename:'assets/assets-map.json',update: true,prettyPrint: true})
var autoprefixer = require('autoprefixer');
var precss = require('precss');
var node_modules = path.join(__dirname,'./node_modules');
var project_name = 'webpack_coc'
module.exports = {
//entry: {'index.entry':"./assets/src/index/index.entry.js"},
entry: {
},
output: {
filename: "[name]-[chunkhash].js",
chunkFilename:'[name]-[chunkhash].js',
path: path.join(__dirname , "./assets/dist/"+project_name),
libraryTarget:'umd',
publicPath:'/'+project_name+'/'//webpack-dev-server build的文件是在内存里的,使用时,在硬盘上看不到生成的文件。这个路径是静态文件的basePath
},
//devtool: 'eval',
externals:{
'react': {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'jquery': {
root: 'jQuery',
commonjs2: 'jquery',
commonjs: 'jquery',
amd: 'jquery'
},
'react-dom':{
root:'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd:'react-dom'
}
//'wscn-common':{
// commonjs2:'wscn-common',
// commonjs:'wscn-common'
//}
},
resolve:{
alias:{
react:path.join(node_modules,'./react/dist/react.min.js'),
jquery:path.join(node_modules,'./jquery/dist/jquery.min.js'),
'react-dom':path.join(node_modules,'./react-dom/dist/react-dom.min.js'),
}
},
module: {
noParse:[
path.join(node_modules,'./react/dist/react.min.js'),
path.join(node_modules,'./jquery/dist/jquery.min.js'),
//path.join(node_modules,'./react-dom/dist/react-dom.min.js')
],
loaders: [
{
test: /[\.jsx|\.js ]$/,
exclude: /node_modules/,
loader: "babel-loader?stage=0&optional[]=runtime"
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap!postcss-loader!less-loader')
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader?name=/img/[name]-[hash].[ext]'
}
]
},
devtool:'sourcemap',
plugins: [
new ExtractTextPlugin("[name]-[chunkhash].css"),
new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$', 'exports', 'require']
}
}),
new webpack.optimize.CommonsChunkPlugin({
name:'commons',
filename:'commons-[chunkhash].js',
minChunks:function(module,count){
//引用测试大于某个次数
if(count>=3){
return true;
}
//符合某种格式
var resourceName = module.resource
if(resourceName){
resourceName = resourceName.substring(resourceName.lastIndexOf(path.sep)+1)
}
var reg = /^(\w)+.common/
if(reg.test(resourceName)){
return true;
}
return false;
}
}),
assetsPluginInstance
],
postcss: function () {
return [autoprefixer, precss];
}
}