From fb1ef44420ac6998b3c01f3c654f355bddd0a58d Mon Sep 17 00:00:00 2001 From: samdelaney Date: Mon, 9 Dec 2024 15:51:26 -0800 Subject: [PATCH] only exit process in `pnpm run build` --- craco.buildconfig.js | 68 ++++++++++++++++++++++++++++++++++++++++++++ craco.config.js | 12 +------- package.json | 2 +- 3 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 craco.buildconfig.js diff --git a/craco.buildconfig.js b/craco.buildconfig.js new file mode 100644 index 0000000..6849c4f --- /dev/null +++ b/craco.buildconfig.js @@ -0,0 +1,68 @@ +const webpack = require('webpack'); + +module.exports = { + webpack: { + configure: (webpackConfig) => { + const wasmExtensionRegExp = /\.wasm$/; + webpackConfig.resolve.extensions.push('.wasm'); + webpackConfig.experiments = { + asyncWebAssembly: true, + lazyCompilation: true, + syncWebAssembly: true, + topLevelAwait: true, + }; + webpackConfig.resolve.fallback = { + ...webpackConfig.resolve.fallback, + fs: false, // fs is not typically available in the browser + crypto: require.resolve('crypto-browserify'), + stream: require.resolve('stream-browserify'), + util: require.resolve('util'), + os: require.resolve('os-browserify/browser'), + path: require.resolve('path-browserify'), + http: require.resolve('stream-http'), + https: require.resolve('https-browserify'), + net: false, // net is not typically available in the browser + tls: false, // tls is not typically available in the browser + dns: require.resolve('dns.js'), + zlib: require.resolve('browserify-zlib'), + url: require.resolve('url'), + buffer: require.resolve('buffer/'), + assert: require.resolve('assert/'), + dgram: false, // dgram is not typically available in the browser + process: require.resolve('process'), + }; + webpackConfig.module.rules.forEach((rule) => { + (rule.oneOf || []).forEach((oneOf) => { + if (oneOf.type === 'asset/resource') { + oneOf.exclude.push(wasmExtensionRegExp); + } + }); + }); + webpackConfig.plugins.push( + new webpack.ProvidePlugin({ + process: 'process', + Buffer: ['buffer', 'Buffer'], + }), + { + apply: (compiler) => { + compiler.hooks.done.tap('DonePlugin', (stats) => { + console.log('Compile is done !'); + setTimeout(() => { + process.exit(0); + }); + }); + } + } + ); + + return webpackConfig; + }, + }, + jest: { + configure: { + globals: { + CONFIG: true, + }, + }, + }, +}; diff --git a/craco.config.js b/craco.config.js index 6849c4f..f34f628 100644 --- a/craco.config.js +++ b/craco.config.js @@ -42,17 +42,7 @@ module.exports = { new webpack.ProvidePlugin({ process: 'process', Buffer: ['buffer', 'Buffer'], - }), - { - apply: (compiler) => { - compiler.hooks.done.tap('DonePlugin', (stats) => { - console.log('Compile is done !'); - setTimeout(() => { - process.exit(0); - }); - }); - } - } + }) ); return webpackConfig; diff --git a/package.json b/package.json index 2014ccc..a6acdfd 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "scripts": { "start": "craco start", - "build": "craco build", + "build": "craco build --config ./craco.buildconfig.js", "test": "jest", "eject": "react-scripts eject", "test-v": "vitest"