Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geopattern adds a large chunk after webpack build #32

Closed
aviaryan opened this issue Jul 25, 2017 · 2 comments
Closed

geopattern adds a large chunk after webpack build #32

aviaryan opened this issue Jul 25, 2017 · 2 comments

Comments

@aviaryan
Copy link
Contributor

aviaryan commented Jul 25, 2017

I see that the minified version of geopattern in this repository is <20kb.
But when I bundle geopattern using webpack, it increases the size of the bundle by around 36kb.
What could be going wrong here?
I am importing geopattern as import GeoPattern from 'geopattern'.
My package.json has only the vendor packages as dependencies.

PS - Sorry, I know this is not the best place to ask this question but I couldn't find anything else.

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

module.exports = {
	entry: {
		app: './src/index.jsx',
		vendor: ['react', 'react-dom', 'geopattern', 'react-router-dom', 'redux']
	},
	module: {
		loaders: [{
			test: /\.jsx?$/,
			exclude: /node_modules/,
			loader: 'babel-loader',
			query: {
				presets: ['es2015', 'react']
			}
		}, {
			test: /\.css$/,
			use:  ExtractTextPlugin.extract({
				use: [{
					loader: 'css-loader',
					options: { importLoaders: 1, modules: true, localIdentName: '[local]-[hash:base64:5]' },
				}],
			}),
		}]
	},
	resolve: {
		extensions: ['.js', '.jsx']
	},
	output: {
		path: __dirname + '/dist',
		publicPath: '/dist/',
		filename: 'bundle.js'
	},
	plugins: [
		// extract text
		new ExtractTextPlugin("styles.css"),
		// minify
		new webpack.optimize.UglifyJsPlugin({
			mangle: true,
			compress: {
				warnings: false, // Suppress uglification warnings
				pure_getters: true,
				unsafe: true,
				unsafe_comps: true,
				screw_ie8: true,
				conditionals: true,
				unused: true,
				comparisons: true,
				sequences: true,
				dead_code: true,
				evaluate: true,
				if_return: true,
				join_vars: true
			},
			comments: false
		}),
		// vendor: https://webpack.github.io/docs/code-splitting.html#split-app-and-vendor-code
		new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'vendor.bundle.js'})
	]
};
@btmills
Copy link
Owner

btmills commented Jul 25, 2017

If I had to guess, webpack is including the buffer shim in the bundle. The Browserify build ignores Node's buffer module because it's an optional fallback that isn't necessary in the browser. There's a webpack issue that talks about excluding buffer. Maybe try that? And if that works, I'd love a PR to add webpack bundling instructions to the readme based on what you find! 💖

@aviaryan
Copy link
Contributor Author

aviaryan commented Jul 25, 2017

@btmills Thanks. Adding a node: { Buffer: false } worked. Reduced bundle size by 22kb.
I will send a PR for this tomorrow.

EDIT - Final webpack config looks something like the following.

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

module.exports = {
	entry: {
		app: './src/index.jsx',
		vendor: ['react', 'react-dom', 'geopattern', 'react-router-dom', 'redux']
	},
	module: {
		loaders: [
		// loaders
		]
	},
	resolve: {
		extensions: ['.js', '.jsx']
	},
	output: {
		path: __dirname + '/dist',
		publicPath: '/dist/',
		filename: 'bundle.js'
	},
	node: { Buffer: false }, 
	plugins: [
		// plugins
	]
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants