Eek out some file size

This commit is contained in:
Aaron Jensen 2015-08-22 11:03:38 -07:00
parent 01b9e772d8
commit 6437d98f73
2 changed files with 21 additions and 16 deletions

View File

@ -4,6 +4,7 @@ var webpack = require('webpack');
module.exports = function createWebpackConfig(_options) { module.exports = function createWebpackConfig(_options) {
var config; var config;
var options = _options || {}; var options = _options || {};
var env = options.env || 'development';
config = { config = {
context: options.context, context: options.context,
@ -11,8 +12,17 @@ module.exports = function createWebpackConfig(_options) {
plugins: [ plugins: [
new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
], ],
node: {
process: false,
},
module: { module: {
loaders: [ loaders: [
{ test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ }, { test: /\.js$/, loaders: ['babel-loader'], exclude: /node_modules/ },
@ -35,6 +45,9 @@ module.exports = function createWebpackConfig(_options) {
config.plugins.push( config.plugins.push(
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
compressor: { compressor: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
screw_ie8: true, screw_ie8: true,
warnings: false, warnings: false,
}, },
@ -42,15 +55,5 @@ module.exports = function createWebpackConfig(_options) {
); );
} }
if (options.env) {
config.plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(options.env),
},
})
);
}
return config; return config;
}; };

View File

@ -43,13 +43,15 @@ describe('u.freeze', () => {
expect(Object.isFrozen(object.foo)).to.be.false; expect(Object.isFrozen(object.foo)).to.be.false;
}); });
it('does not freeze in production', () => { if (typeof process !== 'undefined') {
process.env.NODE_ENV = 'production'; it('does not freeze in production', () => {
const object = {}; process.env.NODE_ENV = 'production';
u.freeze(object); const object = {};
u.freeze(object);
expect(Object.isFrozen(object)).to.be.false; expect(Object.isFrozen(object)).to.be.false;
}); });
}
it('handles null objects', () => { it('handles null objects', () => {
const object = { foo: null }; const object = { foo: null };