1 | var webpack = require("webpack");
|
2 | var path = require('path');
|
3 | var srcDir = 'src/';
|
4 | var fs= require('fs');
|
5 | module.exports = {
|
6 | entry: getEntry(),
|
7 | output: {
|
8 | filename: "[name]"
|
9 | },
|
10 | devtool: '',
|
11 | module: {
|
12 | },
|
13 | plugins: [
|
14 | ],
|
15 | makeConfig:function(ispro,src){
|
16 | var plugins = this.plugins;
|
17 | var devtool = this.devtool;
|
18 | if(ispro){
|
19 | plugins.push(
|
20 | new webpack.optimize.UglifyJsPlugin({
|
21 | compress: {
|
22 | warnings: false
|
23 | }
|
24 | })
|
25 | );
|
26 |
|
27 | }else{
|
28 | devtool="source-map";
|
29 | }
|
30 | return {
|
31 | entry: getEntry(src),
|
32 | output: this.output,
|
33 | module: this.module,
|
34 | devtool: devtool,
|
35 | plugins: plugins
|
36 | }
|
37 | }
|
38 | }
|
39 |
|
40 | function getEntry(src) {
|
41 | if(!src)return;
|
42 |
|
43 | var jsDirPath = path.resolve(src);
|
44 | var dirs = dirlist(jsDirPath);
|
45 | var matchs = [], files = {};
|
46 | dirs.forEach(function (item) {
|
47 | if (/(.+)\.js$/.test(item)) {
|
48 | var rePath = path.relative(jsDirPath,item);
|
49 | files[rePath] = new Array(""+item);
|
50 | }
|
51 | });
|
52 |
|
53 | return files;
|
54 | }
|
55 | function dirlist(src){
|
56 | src = path.resolve(src);
|
57 | var fileList = [];
|
58 | function walk(path){
|
59 | var dirList = fs.readdirSync(path);
|
60 | dirList.forEach(function(item){
|
61 | if(fs.statSync(path + '/' + item).isDirectory()){
|
62 | walk(path + '/' + item);
|
63 | }else{
|
64 | fileList.push(path + '/' + item);
|
65 | }
|
66 | });
|
67 | }
|
68 | walk(src);
|
69 | return fileList
|
70 | } |
\ | No newline at end of file |