Skip to content

Instantly share code, notes, and snippets.

@the-xs
Created March 1, 2017 04:41
Show Gist options
  • Save the-xs/9ee9383ded0109911c505549786f7030 to your computer and use it in GitHub Desktop.
Save the-xs/9ee9383ded0109911c505549786f7030 to your computer and use it in GitHub Desktop.
code-splitting vs tree-shaking
import React from 'react';
import ReactDom from 'react-dom';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import TextField from 'material-ui/TextField';
const App = () => (
<MuiThemeProvider>
<TextField hintText="my cool hint text" />
</MuiThemeProvider>
);
ReactDom.render(<App />, document.body);
{
"name": "splitting-vs-shaking",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"material-ui": "^0.17.0",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"babel-core": "^6.23.1",
"babel-loader": "^6.3.2",
"babel-preset-es2015": "^6.22.0",
"babel-preset-react": "^6.23.0",
"html-webpack-plugin": "^2.28.0",
"webpack": "^2.2.1"
},
"scripts": {
"build:splitting": "webpack --config webpack.splitting.js",
"build:bundle": "webpack --config webpack.bundle.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: {
app: './src/index.js',
},
output: { filename: 'bundle.js', path: 'dist-bundle' },
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
[ 'es2015', { modules: false } ],
'react',
]
}
}
]
},
plugins: [
new HtmlWebpackPlugin({ title: 'bundle' }),
],
}
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: {
app: './src/index.js',
react: ['react', 'react-dom', 'material-ui'],
},
output: { filename: '[name].js', path: 'dist-splitting' },
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: [
[ 'es2015', { modules: false } ],
'react',
]
}
}
]
},
plugins: [
new HtmlWebpackPlugin({ title: 'splitting' }),
new webpack.optimize.CommonsChunkPlugin({
name: 'react'
}),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment