Commons chunk vendor

This commit is contained in:
Kent C. Dodds 2016-07-04 23:32:49 -06:00
parent b306ad39af
commit c7fe4d450f
3 changed files with 23 additions and 9 deletions

View File

@ -17,10 +17,12 @@
"babel-preset-react": "6.11.1", "babel-preset-react": "6.11.1",
"babel-preset-stage-2": "6.13.0", "babel-preset-stage-2": "6.13.0",
"chai": "3.5.0", "chai": "3.5.0",
"cpy-cli": "1.0.1",
"css-loader": "0.23.1", "css-loader": "0.23.1",
"eslint": "3.2.2", "eslint": "3.2.2",
"eslint-config-kentcdodds": "^9.0.0", "eslint-config-kentcdodds": "^9.0.0",
"ghooks": "1.3.2", "ghooks": "1.3.2",
"html-webpack-plugin": "2.22.0",
"http-server": "0.9.0", "http-server": "0.9.0",
"karma": "1.1.2", "karma": "1.1.2",
"karma-chai": "0.1.0", "karma-chai": "0.1.0",
@ -47,9 +49,11 @@
"scripts": { "scripts": {
"prebuild": "rimraf dist", "prebuild": "rimraf dist",
"build": "webpack --env.prod -p", "build": "webpack --env.prod -p",
"postbuild": "cpy favicon.ico dist",
"prebuild:dev": "rimraf dist", "prebuild:dev": "rimraf dist",
"build:dev": "webpack --env.dev", "build:dev": "webpack --env.dev",
"start": "http-server", "postbuild:dev": "cpy favicon.ico dist",
"start": "http-server dist",
"dev": "webpack-dev-server --env.dev --hot", "dev": "webpack-dev-server --env.dev --hot",
"debug": "node-nightly --inspect --debug-brk node_modules/.bin/webpack --env.debug", "debug": "node-nightly --inspect --debug-brk node_modules/.bin/webpack --env.debug",
"debug:dev": "npm run debug -- --env.dev", "debug:dev": "npm run debug -- --env.dev",

View File

@ -3,7 +3,6 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>VanillaJS • TodoMVC</title> <title>VanillaJS • TodoMVC</title>
<script src="dist/bundle.js"></script>
</head> </head>
<body> <body>
<section class="todoapp"> <section class="todoapp">

View File

@ -1,18 +1,22 @@
/* eslint no-console:"off" */ /* eslint no-console:"off" */
const {resolve} = require('path') const {resolve} = require('path')
const webpack = require('webpack')
const ProgressBarPlugin = require('progress-bar-webpack-plugin') const ProgressBarPlugin = require('progress-bar-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const webpackValidator = require('webpack-validator') const webpackValidator = require('webpack-validator')
const {getIfUtils} = require('webpack-config-utils') const {getIfUtils, removeEmpty} = require('webpack-config-utils')
module.exports = env => { module.exports = env => {
const {ifProd, ifNotProd} = getIfUtils(env) const {ifProd, ifNotProd} = getIfUtils(env)
const config = webpackValidator({ const config = webpackValidator({
context: resolve('src'), context: resolve('src'),
entry: './bootstrap.js', entry: {
app: './bootstrap.js',
vendor: ['todomvc-app-css/index.css'],
},
output: { output: {
filename: 'bundle.js', filename: ifProd('bundle.[name].[chunkhash].js', 'bundle.[name].js'),
path: resolve('dist'), path: resolve('dist'),
publicPath: '/dist/',
pathinfo: ifNotProd(), pathinfo: ifNotProd(),
}, },
devtool: ifProd('source-map', 'eval'), devtool: ifProd('source-map', 'eval'),
@ -22,9 +26,16 @@ module.exports = env => {
{test: /\.css$/, loaders: ['style', 'css']}, {test: /\.css$/, loaders: ['style', 'css']},
], ],
}, },
plugins: [ plugins: removeEmpty([
new ProgressBarPlugin() new ProgressBarPlugin(),
], ifProd(new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
})),
new HtmlWebpackPlugin({
template: './index.html',
inject: 'head',
}),
]),
}) })
if (env.debug) { if (env.debug) {
console.log(config) console.log(config)