feat: keeps "build" folder during yarn build

This commit is contained in:
hsluoyz
2025-01-07 23:38:50 +08:00
parent 56d0de64dc
commit 08d6b45fc5
3 changed files with 51 additions and 33 deletions

View File

@ -1,4 +1,5 @@
const CracoLessPlugin = require("craco-less"); const CracoLessPlugin = require("craco-less");
const path = require("path");
module.exports = { module.exports = {
devServer: { devServer: {
@ -55,47 +56,42 @@ module.exports = {
}, },
], ],
webpack: { webpack: {
configure: { configure: (webpackConfig, { env, paths }) => {
paths.appBuild = path.resolve(__dirname, "build-temp");
webpackConfig.output.path = path.resolve(__dirname, "build-temp");
// ignore webpack warnings by source-map-loader // ignore webpack warnings by source-map-loader
// https://github.com/facebook/create-react-app/pull/11752#issuecomment-1345231546 // https://github.com/facebook/create-react-app/pull/11752#issuecomment-1345231546
ignoreWarnings: [ webpackConfig.ignoreWarnings = [
function ignoreSourcemapsloaderWarnings(warning) { function ignoreSourcemapsloaderWarnings(warning) {
return ( return (
warning.module && warning.module &&
warning.module.resource.includes('node_modules') && warning.module.resource.includes("node_modules") &&
warning.details && warning.details &&
warning.details.includes('source-map-loader') warning.details.includes("source-map-loader")
) );
}, },
], ];
// use polyfill Buffer with Webpack 5 // use polyfill Buffer with Webpack 5
// https://viglucci.io/articles/how-to-polyfill-buffer-with-webpack-5 // https://viglucci.io/articles/how-to-polyfill-buffer-with-webpack-5
// https://craco.js.org/docs/configuration/webpack/ // https://craco.js.org/docs/configuration/webpack/
resolve: { webpackConfig.resolve.fallback = {
fallback: { buffer: require.resolve("buffer/"),
// "process": require.resolve('process/browser'), process: false,
// "util": require.resolve("util/"), util: false,
// "url": require.resolve("url/"), url: false,
// "zlib": require.resolve("browserify-zlib"), zlib: false,
// "stream": require.resolve("stream-browserify"), stream: false,
// "http": require.resolve("stream-http"), http: false,
// "https": require.resolve("https-browserify"), https: false,
// "assert": require.resolve("assert/"), assert: false,
"buffer": require.resolve('buffer/'), crypto: false,
"process": false, os: false,
"util": false, fs: false,
"url": false, };
"zlib": false,
"stream": false, return webpackConfig;
"http": false,
"https": false,
"assert": false,
"buffer": false,
"crypto": false,
"os": false,
"fs": false,
}, },
}
}, },
}
}; };

21
web/mv.js Normal file
View File

@ -0,0 +1,21 @@
const fs = require("fs");
const path = require("path");
const sourceDir = path.join(__dirname, "build-temp");
const targetDir = path.join(__dirname, "build");
if (!fs.existsSync(sourceDir)) {
// eslint-disable-next-line no-console
console.error(`Source directory "${sourceDir}" does not exist.`);
process.exit(1);
}
if (fs.existsSync(targetDir)) {
fs.rmSync(targetDir, {recursive: true, force: true});
// eslint-disable-next-line no-console
console.log(`Target directory "${targetDir}" has been deleted successfully.`);
}
fs.renameSync(sourceDir, targetDir);
// eslint-disable-next-line no-console
console.log(`Renamed "${sourceDir}" to "${targetDir}" successfully.`);

View File

@ -57,6 +57,7 @@
"scripts": { "scripts": {
"start": "cross-env PORT=7001 craco start", "start": "cross-env PORT=7001 craco start",
"build": "craco build", "build": "craco build",
"postbuild": "node mv.js",
"test": "craco test", "test": "craco test",
"eject": "craco eject", "eject": "craco eject",
"crowdin:sync": "crowdin upload && crowdin download", "crowdin:sync": "crowdin upload && crowdin download",