fix(webpack): use production mode in production builds (#8007)
This commit is contained in:
parent
8792955f82
commit
19b673e467
|
|
@ -1,15 +1,17 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const HtmlWebPackPlugin = require('html-webpack-plugin');
|
const HtmlWebPackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
|
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
mode,
|
||||||
entry: {
|
entry: {
|
||||||
app: path.join(__dirname, 'index.tsx'),
|
app: path.join(__dirname, 'index.tsx'),
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.js', '.tsx', '.jsx']
|
extensions: ['.ts', '.js', '.tsx', '.jsx']
|
||||||
},
|
},
|
||||||
devtool: 'source-map',
|
devtool: mode === 'production' ? false : 'source-map',
|
||||||
output: {
|
output: {
|
||||||
globalObject: 'self',
|
globalObject: 'self',
|
||||||
filename: '[name].bundle.js',
|
filename: '[name].bundle.js',
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const HtmlWebPackPlugin = require('html-webpack-plugin');
|
const HtmlWebPackPlugin = require('html-webpack-plugin');
|
||||||
|
|
||||||
|
const mode = process.env.NODE_ENV === 'production' ? 'production' : 'development';
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
|
mode,
|
||||||
entry: {
|
entry: {
|
||||||
app: path.join(__dirname, 'index.tsx'),
|
app: path.join(__dirname, 'index.tsx'),
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.js', '.tsx', '.jsx']
|
extensions: ['.ts', '.js', '.tsx', '.jsx']
|
||||||
},
|
},
|
||||||
devtool: 'source-map',
|
devtool: mode === 'production' ? false : 'source-map',
|
||||||
output: {
|
output: {
|
||||||
globalObject: 'self',
|
globalObject: 'self',
|
||||||
filename: '[name].bundle.js',
|
filename: '[name].bundle.js',
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,25 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// @ts-check
|
||||||
|
|
||||||
const child_process = require('child_process');
|
const child_process = require('child_process');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const chokidar = require('chokidar');
|
const chokidar = require('chokidar');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{
|
||||||
|
* command: string,
|
||||||
|
* args: string[],
|
||||||
|
* shell: boolean,
|
||||||
|
* env?: NodeJS.ProcessEnv,
|
||||||
|
* }} Step
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Step[]}
|
||||||
|
*/
|
||||||
const steps = [];
|
const steps = [];
|
||||||
const onChanges = [];
|
const onChanges = [];
|
||||||
const copyFiles = [];
|
const copyFiles = [];
|
||||||
|
|
@ -59,17 +73,23 @@ function runWatch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runBuild() {
|
async function runBuild() {
|
||||||
function runStep(command, args, shell) {
|
/**
|
||||||
const out = child_process.spawnSync(command, args, { stdio: 'inherit', shell });
|
* @param {Step} step
|
||||||
|
*/
|
||||||
|
function runStep(step) {
|
||||||
|
const out = child_process.spawnSync(step.command, step.args, { stdio: 'inherit', shell: step.shell, env: {
|
||||||
|
...process.env,
|
||||||
|
...step.env
|
||||||
|
} });
|
||||||
if (out.status)
|
if (out.status)
|
||||||
process.exit(out.status);
|
process.exit(out.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const step of steps)
|
for (const step of steps)
|
||||||
runStep(step.command, step.args, step.shell);
|
runStep(step);
|
||||||
for (const onChange of onChanges) {
|
for (const onChange of onChanges) {
|
||||||
if (!onChange.committed)
|
if (!onChange.committed)
|
||||||
runStep('node', [filePath(onChange.script)], false);
|
runStep({ command: 'node', args: [filePath(onChange.script)], shell: false });
|
||||||
}
|
}
|
||||||
for (const {files, from, to, ignored} of copyFiles) {
|
for (const {files, from, to, ignored} of copyFiles) {
|
||||||
const watcher = chokidar.watch([filePath(files)], {
|
const watcher = chokidar.watch([filePath(files)], {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue