This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathwebpack.config.js
124 lines (114 loc) · 3.19 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
var webpack = require('webpack')
var path = require('path');
var glob = require('glob');
var moment = require("moment");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var node_modules_dir = path.resolve(__dirname, 'node_modules');
// 判断生产&&测试环境
var isProduction = function () {
return process.env.NODE_ENV === 'production';
};
// 判断开发(热加载)环境
var isHot = function () {
return process.env.NODE_ENV === 'hotdev';
};
// 不同环境输出到不同文件夹
var sEnvironment = function() {
console.log(process.env.NODE_ENV);
switch (process.env.NODE_ENV) {
case 'hotdev':
return 'web/hot/';
case 'production':
return 'web/dist/';
default:
return 'web/dev/';
}
};
function getEntry() {
var entry = {};
var srcDirName = './app/views/js/*.js';
glob.sync(srcDirName).forEach(function (name) {
n = name.slice(name.lastIndexOf('/') + 1, -3);
if (n != 'common') {
entry[n] = name;
}
});
console.log('是否压缩文件:'+isProduction());
console.log('输出路径:'+sEnvironment());
return entry;
}
var packCSS = new ExtractTextPlugin('./css/[name].min.css', {
allChunks: true
});
var config = {
entry: getEntry(),
output: {
path: path.resolve(__dirname, sEnvironment()),
publicPath: isHot() ? sEnvironment() : './',
filename:'[name].min.js',
chunkFilename: '[name].[chunkhash:8].js'
},
module: {
loaders: [{
test: /\.js$/,
exclude: [node_modules_dir],
loader: 'babel',
query: {
presets: ['es2015'],
"ignore": [
"webuploader"
]
}
}, {
test: /\.css$/,
loader:ExtractTextPlugin.extract('style-loader', 'css-loader')
}, {
test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
loader: 'url-loader?limit=512000&name=[path][name].[ext]'
}, {
test: require.resolve('jquery'),
loader: 'expose?jQuery!expose?$'
}]
},
devtool: 'eval',
resolve: {
extensions: ['', '.js', '.jsx', '.less', '.css'],
root: [
path.resolve('./app/views')
],
alias: {
"bootstrap": "vendor/bootstrap.min",
"lazyload": "vendor/jquery.lazyload.min.js",
"webuploader": "vendor/webuploader/webuploader.js",
"layer": "vendor/layer/layer",
"laypage": "vendor/laypage",
"vue": "vendor/vue.min",
"fancybox": "vendor/jquery.fancybox",
"wangEditor": "vendor/wangEditor.js",
"peity": "vendor/jquery.peity.min",
"vue": "vendor/vue.min",
"laypage": "vendor/laypage",
"highlight": "vendor/highlight.pack"
},
},
externals: {
},
plugins: [
packCSS,
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
},
mangle: {
except: ['$', 'webpackJsonpCallback']
}
}),
new webpack.ProvidePlugin({
jQuery: "jquery",
$: "jquery",
"window.jQuery": "jquery"
}),
new webpack.BannerPlugin("Author: ROC\nWebpack Packing Date: " + moment().format("YYYY-MM-DD HH:mm:ss"))
]
};
module.exports = config;