webpack.dll.config.js 4.2 KB
import path from 'path';
import webpack from 'webpack'; 
import HtmlWebpackPlugin from 'html-webpack-plugin';   
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import os from 'os';
const framePath = path.resolve(__dirname, '..');
const DEBUG = !process.argv.includes('--release');
const VERBOSE = process.argv.includes('--verbose'); 


const vendors = [
	'antd', 
	'echarts',
	'element-resize-event',
	'fullcalendar',
	'gregorian-calendar',
	'gregorian-calendar-format',
	'history',
	'jquery', 
	'moment',
	'pinyin',
	'rc-calendar',
	'rc-time-picker',
	'react',
	'react-addons-transition-group', 
	'react-custom-scrollbars',
	'react-datetime',
	'react-dom',
	'react-list',
	'react-month-picker',
	'react-redux',
	'react-router',
	'react-router-redux',
	'react-select', 
	'react-textarea-autosize',
	'redux',
	'redux-form', 
	'redux-thunk',
	'simditor',
	'simditor-emoji',
	'simditor-mention',
	'store2', 
	'classnames',
	'es6-promise',
	'isomorphic-fetch',
	'lodash',
	'uuid',
	'redux-devtools',
	'redux-devtools-dock-monitor',
	'redux-devtools-log-monitor',
	'underscore'
];

const vendor_antd=[
  // 'antd'
];
const GLOBALS = {
  'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"',   
  __DEV__: DEBUG,
  '__DEBUG__'    : DEBUG,
  '__DEBUG_NW__' : false
};

const dllConfig = { 
  resolve: {
    modules: ['node_modules'],
    extensions: [ '.js', '.jsx'] 
  },
  output: {
    path: path.resolve(__dirname, '../temp_build/public'),
    filename: '[name].[chunkhash].js',
    library: '[name]_[chunkhash]',
    publicPath: '/'
  },
  entry: {
    vendor: vendors,
  },
  stats: {
    colors: true,
    reasons: DEBUG,
    hash: VERBOSE,
    version: VERBOSE,
    timings: true,
    chunks: VERBOSE, 
    chunkModules: VERBOSE,
    cached: VERBOSE,
    cachedAssets: VERBOSE,
  },
  // module: {
  // 	loaders: [ 
  //     {
  //       test: /\.(js|jsx?)$/,
  //       loader: 'babel-loader',
  //       include: [
  //         path.resolve(__dirname, '../node_modules/react-routing/src'),
  //         path.resolve(__dirname, '../node_modules/pinyin'),
  //         path.resolve(__dirname, '../src'),
  //       ],
  //       query:{
  //         cacheDirectory: DEBUG,
  //         babelrc: false,
  //         presets: [
  //           'react',
  //           'es2015',
  //           'stage-0',
  //         ],
  //         env:{
  //           development:{
  //             plugins:[
  //               ['react-transform', {
  //                 transforms: [{
  //                   transform: 'react-transform-hmr',
  //                   imports: ['react'],
  //                   locals: ['module']
  //                 }, {
  //                   transform: 'react-transform-catch-errors',
  //                   imports: ['react', 'redbox-react']
  //                 }]
  //               }]
  //             ]
  //           }
  //         },
  //         plugins: [
  //           'transform-runtime',
  //           'add-module-exports'
  //         ]
  //       }
  //     }  
  //   ]
  // },
  plugins: [  
    new webpack.DefinePlugin(GLOBALS),
    new UglifyJsPlugin({
      cache:false,//path.resolve(__dirname, '../.cache/dll'),
      parallel:false,//os.cpus().length,
      uglifyOptions: {
        output: {
          comments: false,  // remove all comments
        },
        mangle:{
          reserved:['$','exports','require']
        },
        compress: {
          warnings: VERBOSE,
        }
      }
    }),
    // new webpack.optimize.UglifyJsPlugin({
    //   output: {
    //     comments: false,  // remove all comments
    //   },
    //   mangle:{
    //     except:['$','exports','require']
    //   },
    //   compress: {
    //     warnings: VERBOSE,
    //   }
    // }),
    // new webpack.optimize.AggressiveMergingPlugin(),
    new webpack.DllPlugin({
      path: path.resolve(__dirname, '../temp_build/manifest.json'), 
      name: '[name]_[chunkhash]' 
    }), 
    new HtmlWebpackPlugin({ 
      "title": 'Custom template',  
      "csrfToken":'<%=htmlWebpackPlugin.options.csrfToken%>',
      "filename": path.resolve(framePath, 'temp_build','index-production.ejs'), 
      "inject":'head',
      "template": path.resolve(framePath, 'server','views','index-dll.ejs')  
    })
  ]
};

export default [dllConfig];