webpack 多入口文件打包

const path = require('path');
const glob = require('glob');
const webpack = require('webpack');
let  entry = getEntry('./resource/**/index.js');
entry['common/common']=['babel-polyfill','vue']
let config = {
  devtool: '#eval-source-map',
  entry:getEntry('./resource/**/index.js'),
  output: {
    path: path.join(__dirname,'/public'),
    publicPath:'/',
    filename: 'script/[name].js'
  },
  module: {
    loaders: [{
      test: /\.vue$/,
      loader: 'vue-loader'
    }, {
      test: /\.js$/,
      loader: 'babel-loader',
      exclude: /node_modules/,
    }, {
      test: /\.(css|less)$/,
      loader: 'style-loader!css-loader!less-loader'
    }, {
      test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
      loader: 'url-loader?limit=8192&name=images/[name]_[hash].[ext]'
    }, {
      test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
      loader: 'url-loader?limit=8192&name=images/[name]_[hash].[ext]',
    }]
  },
  plugins: [
    new webpack.optimize.CommonsChunkPlugin('common/common'),
    new webpack.DllReferencePlugin({
     manifest:'manifest.json',
      context: __dirname,
    })
  ]
}

function getEntry(globPath, options) {
    options = options || {};
    var entries = {},
        basename, tmp, pathname;

    glob.sync(globPath, options).forEach(function (entry) {
        pathname = entry.replace(/\.js$/,'').replace(/^\.\/resource/,'');
        let fpath = entry;
        if(options.cwd){
            fpath = path.join(options.cwd, entry);
        }
        entries[pathname] = ['babel-polyfill',fpath];
    });
    return entries;
}

if(process.env.NODE_ENV === 'production') {
  config.devtool = '#source-map'
  config.plugins = (config.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    })
  ])
}
module.exports = config

你可能感兴趣的:(webpack 多入口文件打包)