-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
executable file
·92 lines (84 loc) · 2.85 KB
/
webpack.config.js
File metadata and controls
executable file
·92 lines (84 loc) · 2.85 KB
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
var webpack = require('webpack')
var WebpackOnBuildPlugin = require('on-build-webpack');
var WebpackPathOrderPlugin = require('path-order-webpack-plugin');
var notifier = require('node-notifier');
var path = require('path')
function webpackDone(title, message, sound){
notifier.notify({
title: title,
message: message,
sound: sound,
icon: path.resolve(__dirname, '/Users/zikong/LingYanSi.github.io/images/wangsitu.jpg')
}, function (err, respond) {
if (err) console.error(err);
});
}
module.exports = {
// 是否缓存
cache: true ,
// 是否监听文件变化
watch: true ,
// 是否在每次打包之前将之前的打包文件
// 删除
clearBeforeBuild: true,
// 入口配置
entry: {
'index': './react/app/pages/index/indexView.jsx',
'about': './react/app/pages/about/aboutView.jsx'
},
// 输出配置
output: {
// 输出路径
path: './react/dist/src/',
filename: "[name].js",
// 块文件名称?
chunkFilename: "[name].js",
},
module:{
// 用来处理文件
loaders: [
// 对js/jsx文件的处理
{ test: /\.(js|jsx)$/ , loader: 'babel-loader' },
// 对less的处理
{ test: /\.less$/, loader: 'style-loader!css-loader!less-loader!autoprefixer-loader' },
{ test: /\.css$/, loader: 'style-loader!css-loader!autoprefixer-loader' }
]
},
// babel需要的 presets / plugins 预设或者插件
babel: {
presets: ['react','es2015','stage-0'] // 把es2015转译成es5,这么做的弊端在于有些浏览器已经支持了新特性,却不能使用
},
// postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ],
// 不需要webpack打包的文件,key: require('key') , value: 全局对象名
externals: {
'react': 'window.React',
'react-dom': 'window.ReactDOM',
'react/addons': 'window.React',
},
resolve:{
alias:{},
unsafeCache: true,
// extensions: ['','js','jsx']
},
// 插件
plugins: [
new WebpackPathOrderPlugin(),
// 打印日志
new WebpackOnBuildPlugin(function(stats) {
var compilation = stats.compilation;
var errors = compilation.errors;
if (errors.length > 0) {
var error = errors[0];
webpackDone(error.name, error.message, 'Glass');
}
else {
var message = 'takes ' + (stats.endTime - stats.startTime) + 'ms';
var warningNumber = compilation.warnings.length;
if (warningNumber > 0) {
message += ', with ' + warningNumber + ' warning(s)';
}
webpackDone('webpack building done', message);
}
})
]
}