Skip to content

Commit

Permalink
only exit process in pnpm run build
Browse files Browse the repository at this point in the history
  • Loading branch information
SamDelaney committed Dec 9, 2024
1 parent b7ed683 commit fb1ef44
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
68 changes: 68 additions & 0 deletions craco.buildconfig.js
Original file line number Diff line number Diff line change
@@ -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,
},
},
},
};
12 changes: 1 addition & 11 deletions craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fb1ef44

Please sign in to comment.