feat(v2): don't output server.bundle.js to disk (#1361)

This commit is contained in:
Endilie Yacop Sucipto 2019-04-13 16:23:33 +07:00 committed by GitHub
parent fbfb26e17c
commit ecb4f91669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -7,6 +7,7 @@
const webpack = require('webpack'); const webpack = require('webpack');
const merge = require('webpack-merge'); const merge = require('webpack-merge');
const MemoryFS = require('memory-fs');
const CleanWebpackPlugin = require('clean-webpack-plugin'); const CleanWebpackPlugin = require('clean-webpack-plugin');
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer'); const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const path = require('path'); const path = require('path');
@ -18,9 +19,14 @@ const createServerConfig = require('../webpack/server');
const createClientConfig = require('../webpack/client'); const createClientConfig = require('../webpack/client');
const {applyConfigureWebpack} = require('../webpack/utils'); const {applyConfigureWebpack} = require('../webpack/utils');
function compile(config) { function compile(config, isServer) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
webpack(config, (err, stats) => { const compiler = webpack(config);
if (isServer) {
// Don't output server bundle to disk. Write files to memory instead
compiler.outputFileSystem = new MemoryFS();
}
compiler.run((err, stats) => {
if (err) { if (err) {
reject(err); reject(err);
} }
@ -84,7 +90,7 @@ module.exports = async function build(siteDir, cliOptions = {}) {
await compile(clientConfig); await compile(clientConfig);
// Build the server bundles (render the static HTML and pick client bundle), // Build the server bundles (render the static HTML and pick client bundle),
await compile(serverConfig); await compile(serverConfig, true);
// Copy static files. // Copy static files.
const staticDir = path.resolve(siteDir, 'static'); const staticDir = path.resolve(siteDir, 'static');

View file

@ -55,6 +55,7 @@
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"is-wsl": "^1.1.0", "is-wsl": "^1.1.0",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"memory-fs": "^0.4.1",
"mini-css-extract-plugin": "^0.4.1", "mini-css-extract-plugin": "^0.4.1",
"portfinder": "^1.0.13", "portfinder": "^1.0.13",
"react-dev-utils": "^8.0.0", "react-dev-utils": "^8.0.0",