webpack.config.dev.js 1.22 KB
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')
	]
}