forked from Cathy0807/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.production.config.js
51 lines (49 loc) · 1.21 KB
/
webpack.production.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
var webpack = require('webpack');
var path = require('path');
var loaders = require('./webpack.loaders');
var CopyWebpackPlugin = require('copy-webpack-plugin');
//先清空build文件夹下的文件
var fs = require('fs');
var buildPath='./build/';
var folder_exists = fs.existsSync(buildPath);
if(folder_exists == true)
{
var dirList = fs.readdirSync(buildPath);
dirList.forEach(function(fileName)
{
fs.unlinkSync(buildPath + fileName);
});
console.log("clearing " + buildPath);
};
module.exports = {
//入口文件配置
entry: [
'./index.jsx' // Your appʼs entry point
],
//输出文件配置
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js'
},
//更多配置项
resolve: {
extensions: ['', '.js', '.jsx'] //自动扩展文件后缀名,意味着我们require模块可以省略不写后缀名
},
//文件的加载配置
module: {
loaders: loaders
},
//插件配置
plugins: [
//Webpack提供了设置环境变量来优化代码的方案
new webpack.DefinePlugin({
'process.env':{
'NODE_ENV': JSON.stringify('production')
}
}),
//复制文件到构建目录
new CopyWebpackPlugin([
{from: './index.html'}
])
]
};