Skip to content

Commit

Permalink
Combine webpack configs
Browse files Browse the repository at this point in the history
We don't need to have two different webpack processes playing off of
each other when we can supply two different configs for the same process
  • Loading branch information
Jeremia Kimelman committed Jul 10, 2017
1 parent d6cac09 commit efa6d89
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 126 deletions.
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
"scripts": {
"start": "node build/server.js",
"postinstall": "npm run swagger",
"build": "export NODE_ENV=production && npm run build:client && npm run build:server && unset NODE_ENV",
"build:client": "webpack -p --progress --config webpack.client.config.js",
"build:server": "webpack --config webpack.server.config.js",
"watch": "npm run watch:server & npm run watch:client",
"watch:server": "webpack -w --config webpack.server.config.js & nodemon build/server.js",
"watch:client": "webpack -w --progress --config webpack.client.config.js",
"build": "export NODE_ENV=production && webpack -p --progress --config webpack.config.js && unset NODE_ENV",
"watch": "webpack -w --progress --config webpack.config.js & nodemon build/server.js",
"lint": "npm run lint:js && npm run lint:yml",
"lint:js": "eslint src scripts server.js --ignore-path .gitignore || exit 0",
"lint:yml": "yamllint content/**/*.yml || exit 0",
Expand Down
75 changes: 0 additions & 75 deletions webpack.client.config.js

This file was deleted.

109 changes: 109 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/* eslint-disable comma-dangle, no-param-reassign, no-var, quote-props */
const fs = require('fs')
const path = require('path')

const autoprefixer = require('autoprefixer')
const CompressionPlugin = require('compression-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')

const webpack = require('webpack')

const env = process.env.NODE_ENV || 'development'

const clientConfig = {
entry: './src/entry.js',
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!autotrack|dom-utils)/,
loader: 'babel-loader',
},
{
test: /\.scss$/i,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: [autoprefixer('last 2 versions', '> 5%')],
},
},
{
loader: 'sass-loader',
options: {
outputStyle: 'compressed',
includePaths: ['node_modules'],
},
},
],
}),
},
{
test: /\.ya*ml$/,
use: ['json-loader', 'yaml-loader'],
},
],
},
plugins: [
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$/,
threshold: 10240,
minRatio: 0.8,
}),
new ExtractTextPlugin('app.css'),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(env),
},
}),
],
}

const serverConfig = {
cache: false,
entry: './src/server.js',
output: {
path: path.join(__dirname, 'build'),
filename: 'server.js',
},
target: 'node',
node: {
__dirname: false,
},
externals: fs
.readdirSync('node_modules')
.filter(x => ['.bin'].indexOf(x) === -1)
.reduce((nodeModules, mod) => {
nodeModules[mod] = `commonjs ${mod}`
return nodeModules
}),
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!autotrack|dom-utils)/,
loader: 'babel-loader',
},
{
test: /\.ya*ml$/,
use: ['json-loader', 'yaml-loader'],
},
],
},
plugins: [new webpack.IgnorePlugin(/\.(css|less)$/)],
}

if (env === 'production') {
clientConfig.plugins.push(new webpack.optimize.UglifyJsPlugin())
}

module.exports = [serverConfig, clientConfig]
45 changes: 0 additions & 45 deletions webpack.server.config.js

This file was deleted.

0 comments on commit efa6d89

Please sign in to comment.