-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.dev.js
More file actions
88 lines (82 loc) · 2.75 KB
/
webpack.config.dev.js
File metadata and controls
88 lines (82 loc) · 2.75 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
var path = require("path");
var webpack = require("webpack");
var fs = require("fs");
var node_modules = path.resolve(__dirname, 'node_modules');
var publishTime = new Date().getFullYear().toString() + (new Date().getMonth() + 1).toString() +
new Date().getDate().toString() + new Date().getHours().toString();
var config = {
entry: {
/*首页*/
index: './app/entry/index/index.js',
/*redux*/
redux: './app/entry/redux/index.js',
/*ant design*/
animation: './app/entry/animation/index.js',
/*page*/
page: './app/entry/page/index.js',
/*postCss*/
css: './app/entry/postCss/index.js'
},
output: {
path: path.join(__dirname, 'build/'),
filename: 'js/[name]_' + publishTime + '.js',
chunkFilename: "js/[id].js",
publicPath: ''
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: 'js/vendors_' + publishTime + '.js' })
],
module: {
loaders: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader?-babelrc,+cacheDirectory,presets[]=es2015,presets[]=react',
exclude: /node_modules/,
},
{test: /\.(css|pcss)$/, loader: 'style-loader!css-loader!postcss-loader'},
{test: /\.(png|jpg|gif|ttf|eot|woff|woff2|svg)$/, loader: 'url-loader?limit=8192&name=resource/[name].[ext]'},
{test: /\.swf$/, loader: "file?name=js/[name].[ext]"}
]
},
resolve: {
extensions: ['.js','.jsx','.coffee','.pcss']
}
};
module.exports = config;
var template = '<!DOCTYPE html> \n\
<html lang="en"> \n\
<head> \n\
<meta charset="UTF-8"> \n\
<meta http-equiv="X-UA-Compatible" content="IE=edge"> \n\
<title>react-locke</title> \n\
</head> \n\
<body> \n\
<div id="container"></div> \n\
<script src="js/vendors.js"></script> \n\
<script src="js/key.js"></script> \n\
</body> \n\
</html> \n';
var deleteFolderRecursive = function (path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function (file, index) {
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
deleteFolderRecursive("./build/js");
for (var key in config.entry) {
var targetFile = "./build/" + key + ".html";
var result = template.replace("key", key + "_" + publishTime);
result = result.replace("vendors", "vendors_" + publishTime);
fs.writeFile(targetFile, result, 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
}