-
-
Save imrvelj/75abd2578d7b07cb4526cd572100887d to your computer and use it in GitHub Desktop.
Tree-Shaking with Babel 6, Webpack 2, and React.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": [ | |
["es2015", { | |
"es2015": { | |
"loose": true, | |
"modules": false | |
} | |
}], "react" | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
const App = React.createClass({ | |
render() { | |
return ( | |
<div>Hello World</div> | |
); | |
} | |
}); | |
ReactDOM.render(<App/>, document.querySelector('#app')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "babel6-webpack2-react-tree-shaking", | |
"version": "0.0.0", | |
"dependencies": {}, | |
"devDependencies": { | |
"babel-core": "6.18.2", | |
"babel-loader": "6.2.8", | |
"babel-preset-es2015": "6.18.0", | |
"babel-preset-react": "6.16.0", | |
"babili": "0.0.9", | |
"babili-webpack-plugin": "0.0.7", | |
"http-server": "0.9.0", | |
"react": "15.4.1", | |
"react-dom": "15.4.1", | |
"webpack": "2.1.0-beta.27" | |
}, | |
"scripts": { | |
"build": "webpack --config webpack.config.js", | |
"start": "http-server -a 0.0.0.0 -p 9000" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BabiliPlugin = require('babili-webpack-plugin'); | |
const path = require('path'); | |
const webpack = require('webpack'); | |
module.exports = { | |
entry: { | |
'app': './app.js' | |
}, | |
output: { | |
path: './dist', | |
filename: '[name].bundle.js' | |
}, | |
module: { | |
rules: [{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
query: { | |
presets: [ | |
'es2015', | |
'react' | |
], | |
plugins: [] | |
}, | |
include: [ | |
path.resolve(__dirname, 'app') | |
] | |
}, { | |
test: /\.json$/, | |
loader: "json-loader" | |
}] | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'production') | |
}), | |
new BabiliPlugin() | |
], | |
resolve: { | |
modules: [ | |
path.join(process.cwd(), 'app'), | |
'node_modules' | |
], | |
extensions: ['.js', '.json'] | |
}, | |
devtool: false | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment