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-stage-2": "6.13.0",
"chai": "3.5.0",
"cpy-cli": "1.0.1",
"css-loader": "0.23.1",
"eslint": "3.2.2",
"eslint-config-kentcdodds": "^9.0.0",
"ghooks": "1.3.2",
"html-webpack-plugin": "2.22.0",
"http-server": "0.9.0",
"karma": "1.1.2",
"karma-chai": "0.1.0",
@ -47,9 +49,11 @@
"scripts": {
"prebuild": "rimraf dist",
"build": "webpack --env.prod -p",
"postbuild": "cpy favicon.ico dist",
"prebuild:dev": "rimraf dist",
"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",
"debug": "node-nightly --inspect --debug-brk node_modules/.bin/webpack --env.debug",
"debug:dev": "npm run debug -- --env.dev",

View File

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

View File

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