var webpack = require('webpack');

// 辅助函数
var utils = require('./utils');
var fullPath  = utils.fullPath;
var pickFiles = utils.pickFiles;

// 项目根路径
var ROOT_PATH = fullPath('../');
// 项目源码路径
var SRC_PATH = ROOT_PATH + '/src';
// 产出路径
var DIST_PATH = ROOT_PATH + '/dist';

// 是否是开发环境
var __DEV__ = !(process.env.NODE_ENV === 'production');

// conf
var alias = pickFiles({
  id: /(conf\/[^\/]+).js$/,
  pattern: SRC_PATH + '/conf/*.js'
});

// components
alias = Object.assign(alias, pickFiles({
  id: /(components\/[^\/]+)/,
  pattern: SRC_PATH + '/components/*/index.js'
}));

// reducers
alias = Object.assign(alias, pickFiles({
  id: /(reducers\/[^\/]+).js/,
  pattern: SRC_PATH + '/js/reducers/*'
}));

// actions
alias = Object.assign(alias, pickFiles({
  id: /(actions\/[^\/]+).js/,
  pattern: SRC_PATH + '/js/actions/*'
}));


var config = {
  context: SRC_PATH,
  entry: {
    app: ['./pages/app.js']
  },
  output: {
    path: DIST_PATH,
    filename: 'js/bundle.js'
  },
  module: {},
  resolve: {
    alias: alias
  },
  plugins: [
    new webpack.DefinePlugin({
      __DEV__: __DEV__
    })
  ]
};


var CACHE_PATH = ROOT_PATH + '/cache';
// loaders
config.module.loaders = [];
// 使用 babel 编译 jsx、es6
config.module.loaders.push({
  test: /\.js$/,
  exclude: /node_modules/,
  include: SRC_PATH,
  // 这里使用 loaders ，因为后面还需要添加 loader
  loaders: ['babel?cacheDirectory=' + CACHE_PATH]
});
// 编译 sass
config.module.loaders.push({
  test: /\.(scss|css)$/,
  loaders: ['style', 'css', 'sass', 'postcss']
});

// autoprefix
var precss = require('precss');
var autoprefixer = require('autoprefixer');
config.postcss = function() {
  return [precss, autoprefixer];
}

// html 页面
var HtmlwebpackPlugin = require('html-webpack-plugin');
config.plugins.push(
  new HtmlwebpackPlugin({
    filename: 'index.html',
    chunks: ['app'],
    template: SRC_PATH + '/pages/app.html'
  })
);

module.exports = config;





@@ -265,16 +265,86 @@
 '/dist';
+%0A// node_modules%0Avar NODE_MODULES_PATH =  ROOT_PATH + '/node_modules';
 %0A%0A// %E6%98%AF%E5%90%A6%E6%98%AF
@@ -401,24 +401,25 @@
 duction');%0A%0A
+%0A
 // conf%0Avar 
@@ -974,16 +974,123 @@
 app.js'%5D
+,%0A    lib: %5B%0A      'react', 'react-dom', 'react-router',%0A      'redux', 'react-redux', 'redux-thunk'%0A    %5D,
 %0A  %7D,%0A  
@@ -1142,14 +1142,14 @@
 'js/
-bundle
+%5Bname%5D
 .js'
@@ -1280,17 +1280,93 @@
   %7D)
-%0A  %5D%0A%7D;%0A%0A
+,%0A    new webpack.optimize.CommonsChunkPlugin('lib', 'js/lib.js')%0A  %5D%0A%7D;%0A%0A%0A// loaders
 %0Avar
@@ -1401,27 +1401,16 @@
 cache';%0A
-// loaders%0A
 config.m
@@ -1753,18 +1753,23 @@
 '%5D%0A%7D);%0A%0A
+%0A
 //
+ css
  autopre
@@ -1914,16 +1914,17 @@
 er%5D;%0A%7D%0A%0A
+%0A
 // html 
@@ -2075,16 +2075,23 @@
 : %5B'app'
+, 'lib'
 %5D,%0A    t
@@ -2137,16 +2137,17 @@
  %7D)%0A);%0A%0A
+%0A
 module.e

打包合并 js、css