diff --git a/web/craco.config.js b/web/craco.config.js index 9222efd9..a2f55393 100644 --- a/web/craco.config.js +++ b/web/craco.config.js @@ -1,4 +1,5 @@ const CracoLessPlugin = require("craco-less"); +const path = require("path"); module.exports = { devServer: { @@ -55,47 +56,42 @@ module.exports = { }, ], webpack: { - configure: { - // ignore webpack warnings by source-map-loader + 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 // https://github.com/facebook/create-react-app/pull/11752#issuecomment-1345231546 - ignoreWarnings: [ + webpackConfig.ignoreWarnings = [ function ignoreSourcemapsloaderWarnings(warning) { return ( warning.module && - warning.module.resource.includes('node_modules') && + warning.module.resource.includes("node_modules") && warning.details && - warning.details.includes('source-map-loader') - ) + warning.details.includes("source-map-loader") + ); }, - ], + ]; + // use polyfill Buffer with Webpack 5 // https://viglucci.io/articles/how-to-polyfill-buffer-with-webpack-5 // https://craco.js.org/docs/configuration/webpack/ - resolve: { - fallback: { - // "process": require.resolve('process/browser'), - // "util": require.resolve("util/"), - // "url": require.resolve("url/"), - // "zlib": require.resolve("browserify-zlib"), - // "stream": require.resolve("stream-browserify"), - // "http": require.resolve("stream-http"), - // "https": require.resolve("https-browserify"), - // "assert": require.resolve("assert/"), - "buffer": require.resolve('buffer/'), - "process": false, - "util": false, - "url": false, - "zlib": false, - "stream": false, - "http": false, - "https": false, - "assert": false, - "buffer": false, - "crypto": false, - "os": false, - "fs": false, - }, - } + webpackConfig.resolve.fallback = { + buffer: require.resolve("buffer/"), + process: false, + util: false, + url: false, + zlib: false, + stream: false, + http: false, + https: false, + assert: false, + crypto: false, + os: false, + fs: false, + }; + + return webpackConfig; }, - } + }, }; diff --git a/web/mv.js b/web/mv.js new file mode 100644 index 00000000..dbbfd7cf --- /dev/null +++ b/web/mv.js @@ -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.`); diff --git a/web/package.json b/web/package.json index 3d9d210d..2fc14f42 100644 --- a/web/package.json +++ b/web/package.json @@ -57,6 +57,7 @@ "scripts": { "start": "cross-env PORT=7001 craco start", "build": "craco build", + "postbuild": "node mv.js", "test": "craco test", "eject": "craco eject", "crowdin:sync": "crowdin upload && crowdin download",