var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

// 将npm中的模块在webpack打包时变成require(moduleName)
// 而不是将代码打包进去
var npmModules = Object.keys(require('./package.json').dependencies);
var externals = {};
npmModules.forEach(function(npmModule){
	if(npmModule === 'vue'){
		var file = 'vue.js';
		if(process.env.NODE_ENV === 'production'){
			file = 'vue.min.js';
		}
		externals[npmModule] = 'commonjs ' + npmModule + '/dist/' + file;
		return;
	}
	externals[npmModule] = 'commonjs ' + npmModule;
});

module.exports = {
	entry: ['./main.js'],
	target: 'electron',
	output: {
		path: __dirname,
		filename: 'bundle.js'
	},
	module: {
		rules: [{
			test: /\.vue$/,
			use:{
				loader: 'vue-loader'
			}
		},{
			test: /\.png$/,
			use:{
				loader: 'url-loader?limit=100000'
			}
		},{
			test: /\.js$/,
			exclude: /node_modules/,
			use:{
				loader: 'babel-loader',
				options: {
					// presets: ['es2015','stage-0'],
					// plugins: ['transform-runtime']
				}
			}
		},{
			test: /\.css$/,
            // exclude: /\-module\.css$/,
            // loader: ExtractTextPlugin.extract('style-loader','css-loader?root=' + path.normalize(__dirname + '/htdocs').replace(/\\/g,'/'))
            // loader: ExtractTextPlugin.extract('style-loader','css-loader')
			use: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })
		}]
	},
	plugins: [
		new ExtractTextPlugin('style/bundle.css'),
		new webpack.DefinePlugin({
			DEBUG: process.env.NODE_ENV !== 'production',
			CLOUD: !!process.env.CLOUD
		})
	],
	externals: externals,
	devtool: process.env.NODE_ENV === 'production' ? '' : '#source-map'
};

@@ -27,16 +27,44 @@
 pack');%0A
+var path = require('path');%0A
 var Extr
@@ -119,17 +119,16 @@
 ugin');%0A
-%0A
 // %E5%B0%86npm%E4%B8%AD
@@ -1602,16 +1602,20 @@
 ernals: 
+%5B%0A%09%09
 external
@@ -1617,16 +1617,282 @@
 ernals,%0A
+%09%09function(context, request, callback)%7B%0A%09%09%09if(/ace%5C//.test(request))%7B%0A%09%09%09%09return callback(null, 'commonjs2 ' + request);%0A%09%09%09%7D%0A%09%09%09if(/npm_modules%5C//.test(request))%7B%0A%09%09%09%09return callback(null, 'commonjs2 ./' + path.relative('..', request));%0A%09%09%09%7D%0A%09%09%09callback();%0A%09%09%7D%0A%09%5D,%0A
 %09devtool

更新打包配置，去掉npm模块，优化性能 #42