From a471a33014264242442c017bc87ab9151378ec24 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Fri, 30 Mar 2018 17:05:33 -0400 Subject: [PATCH] Splitting prod configs --- package.json | 5 +-- webpack.prod-prerender.js | 40 +++++++++++++++++++++ webpack.prod-web.js | 32 +++++++++++++++++ webpack.prod.js | 74 --------------------------------------- 4 files changed, 75 insertions(+), 76 deletions(-) create mode 100644 webpack.prod-prerender.js create mode 100644 webpack.prod-web.js delete mode 100644 webpack.prod.js diff --git a/package.json b/package.json index 3d4938c..3568ade 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,9 @@ "start": "webpack-dev-server --config webpack.dev.js", "start:prod": "run-s build start:http-server", "start:http-server": "http-server ./build", - "build": "cross-env NODE_ENV=production run-s build:webpack build:prerender", - "build:webpack": "webpack --config webpack.prod.js", + "build": "cross-env NODE_ENV=production run-s build:webpack:web build:webpack:prerender build:prerender", + "build:webpack:web": "webpack --config webpack.prod-web.js", + "build:webpack:prerender": "webpack --config webpack.prod-prerender.js", "build:prerender": "node ./script/__build__/prerender.js", "test": "run-s test:lint 'test:unit --coverage'", "test:unit": "cross-env NODE_ENV=production jest", diff --git a/webpack.prod-prerender.js b/webpack.prod-prerender.js new file mode 100644 index 0000000..9a7e673 --- /dev/null +++ b/webpack.prod-prerender.js @@ -0,0 +1,40 @@ +const path = require('path'); +const webpack = require('webpack'); +const common = require('./webpack.common.js'); +const nodeExternals = require('webpack-node-externals'); + +module.exports = { + mode: 'production', + target: 'node', + externals: [nodeExternals({ + whitelist: [ /\.svg$/ ] + })], + entry: { + prerender: './script/prerender.js' + }, + output: { + filename: '[name].js', + chunkFilename: '[name].chunk.js', + path: path.resolve(__dirname, 'script/__build__') + }, + resolve: { + modules: ['src', 'node_modules'] + }, + plugins: [ + // Only want the EnvironmentPlugin + common.plugins.find(plugin => plugin instanceof webpack.EnvironmentPlugin) + ], + module: { + rules: [ + // Replace the rule for CSS files + { + test: /\.css$/, + loader: 'css-loader/locals', + options: { + modules: true + } + }, + ...common.module.rules.filter(rule => !rule.test.test('file.css')) + ] + } +}; diff --git a/webpack.prod-web.js b/webpack.prod-web.js new file mode 100644 index 0000000..0c260c4 --- /dev/null +++ b/webpack.prod-web.js @@ -0,0 +1,32 @@ +const merge = require('webpack-merge'); +const common = require('./webpack.common.js'); +const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); +const { GenerateSW } = require('workbox-webpack-plugin'); + +module.exports = merge(common, { + mode: 'production', + devtool: 'source-map', + plugins: [ + new UglifyJSPlugin({ + sourceMap: true + }), + new GenerateSW({ + clientsClaim: true, + skipWaiting: true, + runtimeCaching: [ + { + urlPattern: /https?:\/\/licensebuttons\.net/, + handler: 'staleWhileRevalidate' + }, + { + urlPattern: /https?:\/\/fonts\.googleapis\.com/, + handler: 'staleWhileRevalidate' + }, + { + urlPattern: /https?:\/\/fonts\.gstatic\.com/, + handler: 'staleWhileRevalidate' + } + ] + }) + ] +}); diff --git a/webpack.prod.js b/webpack.prod.js deleted file mode 100644 index de38a43..0000000 --- a/webpack.prod.js +++ /dev/null @@ -1,74 +0,0 @@ -const path = require('path'); -const webpack = require('webpack'); -const merge = require('webpack-merge'); -const common = require('./webpack.common.js'); -const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); -const { GenerateSW } = require('workbox-webpack-plugin'); -const nodeExternals = require('webpack-node-externals'); - -module.exports = [ - // Web - merge(common, { - mode: 'production', - devtool: 'source-map', - plugins: [ - new UglifyJSPlugin({ - sourceMap: true - }), - new GenerateSW({ - clientsClaim: true, - skipWaiting: true, - runtimeCaching: [ - { - urlPattern: /https?:\/\/licensebuttons\.net/, - handler: 'staleWhileRevalidate' - }, - { - urlPattern: /https?:\/\/fonts\.googleapis\.com/, - handler: 'staleWhileRevalidate' - }, - { - urlPattern: /https?:\/\/fonts\.gstatic\.com/, - handler: 'staleWhileRevalidate' - } - ] - }) - ] - }), - // Node (prerender) - { - mode: 'production', - target: 'node', - externals: [nodeExternals({ - whitelist: [ /\.svg$/ ] - })], - entry: { - prerender: './script/prerender.js' - }, - output: { - filename: '[name].js', - chunkFilename: '[name].chunk.js', - path: path.resolve(__dirname, 'script/__build__') - }, - resolve: { - modules: ['src', 'node_modules'] - }, - plugins: [ - // Only want the EnvironmentPlugin - common.plugins.find(plugin => plugin instanceof webpack.EnvironmentPlugin) - ], - module: { - rules: [ - // Replace the rule for CSS files - { - test: /\.css$/, - loader: 'css-loader/locals', - options: { - modules: true - } - }, - ...common.module.rules.filter(rule => !rule.test.test('file.css')) - ] - } - } -];