webpack.config.js
1.74 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
var path = require('path');
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var fs=require('fs'),
path=require('path');
var commons=[];
var config = JSON.parse(fs.readFileSync('./package.json').toString());
var spmroot=path.join(__dirname, 'spm_modules');
var alias={};
for(key in config.spm.dependencies){
var edition=path.join(key,config.spm.dependencies[key]);
var json=path.join(spmroot,path.join(edition,'package.json'));
var mainjs=JSON.parse(fs.readFileSync(json).toString()).spm.main;
if(!alias[key]){
alias[key]=path.join(edition,mainjs).replace('/\\/ig','/');
}
}
for (key in config.spm.dependencies) {
commons.push(key);
}
var entry={index:[],libs:[]};
console.log(commons);
entry.libs=commons;
var index=["./js/index","./js/main1",'./js/coupon/edit','./js/coupon/index','./js/supplier/index','./js/supplier/edit'
,'./js/supplier/info','./js/brand/edit','./js/brand/index','./js/product/add','./js/product/index','./js/store/adminedit','./js/store/adminindex'
,'./js/store/examine','./js/store/indexlist','./js/store/info','./js/store/check','./js/store/index'
,'./js/limitcode/edit','./js/limitcode/index','./js/product/attr'];
for(var i in index){
var __name=index[i].replace(/(.\/js)|\//g,'');
entry[__name]=index[i];
}
var plugins=[
//获取公共js
new webpack.optimize.CommonsChunkPlugin('libs','libs.js')
//全局引入jquery
// new webpack.ProvidePlugin({
// $: "jquery",
// jQuery: "jquery",
// "window.jQuery": "jquery"
// })
];
module.exports = {
entry: entry,
output: {
filename:'[name].js'
},
resolve:{
root: [spmroot],
extension:['','.js'],
alias:alias
},
plugins:plugins
};