Skip to content

Instantly share code, notes, and snippets.

@lucasbento
Created February 9, 2017 20:35
Show Gist options
  • Save lucasbento/3a94435f5dfa7a5d38321f81710774f5 to your computer and use it in GitHub Desktop.
Save lucasbento/3a94435f5dfa7a5d38321f81710774f5 to your computer and use it in GitHub Desktop.
Webpack 2 Tree Shaking
{
"presets": [
["es2015", {
"modules": false
}],
"react",
"stage-0"
],
"compact": "true",
"plugins": [
["transform-relay-hot", {
"schemaJsonFilepath": "./data/schema.json",
"watchInterval": 2000
}]
],
"env": {
"development": {
"plugins": [
"transform-react-jsx-source"
]
}
}
}
{
...
"scripts": {
"build": "webpack --config webpack.prod.config.js --progress --profile --colors"
}
...
}
/* eslint-disable */
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanPlugin = require('clean-webpack-plugin');
const dotEnv = require('dotenv-webpack');
module.exports = {
// Default folder for code source
context: path.join(__dirname, './src'),
devtool: 'hidden-source-map',
entry: './index.js',
output: {
path: path.join(__dirname, 'admin'),
publicPath: '/admin/',
filename: '[chunkhash].js'
},
resolve: {
modules: [
path.join(__dirname, 'src'),
'node_modules',
],
extensions: ['.js'],
},
module: {
rules: [{
test: /\.js?$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
options: {
babelrc: false,
presets: [
['es2015', { modules: false }],
'react',
'stage-0',
],
}
},
],
// include: path.join(__dirname, 'src'),
}],
},
plugins: [
new dotEnv({
path: './.env',
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
drop_console: true,
drop_debugger: true,
dead_code: true,
unused: true,
},
}),
new CleanPlugin(['admin'], { verbose: false }),
new HtmlWebpackPlugin({
template: './index.html'
}),
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment