webpack.config.dev.js
1.22 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
var fs=require('fs'),
path=require('path');
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var config = JSON.parse(fs.readFileSync('./package.json').toString());
var baseName="./static/js.jquery";
var entry={
index:[],
libs:[baseName+"/common/common.js"]
};
var readfile=function(dir,callback){
var files = fs.readdirSync(dir);
files.forEach(function (file) {
var filePath = path.join(dir, file);
if (fs.statSync(filePath).isFile() && /.*\.js$/i.test(file)) {
callback && callback(filePath);
}else{
if(file != "partials"&&file!='.DS_Store'){
readfile(filePath,callback);
}
}
});
}
var index=[];
readfile(baseName+"/module",function(src){
index.push(src);
});
for(var i in index){
var dirs=index[i].match(/(\w+)/g)
dirs.splice(0,4);
dirs.length=dirs.length-1;
entry[dirs.join('.')]='.'+path.sep+index[i];
}
module.exports = {
entry:entry,
output:{
filename: "[name].js",
path: "../dist/" + config.version + "/static/jquery"
},
resolve: {
alias: {
jquery: path.resolve(baseName, './jquery.js')
}
},
plugins:[
new webpack.optimize.CommonsChunkPlugin('libs','libs.js')
]
}