diff --git a/.changeset/pink-houses-lose.md b/.changeset/pink-houses-lose.md new file mode 100644 index 000000000..916232178 --- /dev/null +++ b/.changeset/pink-houses-lose.md @@ -0,0 +1,5 @@ +--- +"@alauda/ui": patch +--- + +fix: hack for rspack module federation due to `dayjs -> dayjs/esm` alias diff --git a/package.json b/package.json index bceb8611a..5f726c0ac 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,6 @@ ], "scripts": { "build": "node scripts/build.js", - "build:copy": "node scripts/copy-resources", - "build:lib": "ng-packagr -c tsconfig.lib.json", "build:watch": "node scripts/build.js --watch", "debug": "node scripts/build.js --debug --watch", "dev": "yarn start", diff --git a/scripts/build.js b/scripts/build.js index 0c326f9cd..c6936ad08 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,3 +1,4 @@ +const fs = require('node:fs/promises'); const path = require('node:path'); const gulp = require('gulp'); @@ -13,7 +14,7 @@ const debugNgPackage = '../ng-package.debug.json'; const releaseDest = isDebug ? require(debugNgPackage).dest : 'release'; -function copyResources() { +async function afterBuild() { const themeDest = path.resolve(releaseDest, 'theme'); gulp .src([ @@ -29,6 +30,17 @@ function copyResources() { .src('src/theme/style.scss') .pipe(sass().on('error', sass.logError)) .pipe(gulp.dest(themeDest)); + + // hack for rspack module federation due to `dayjs -> dayjs/esm` alias + const esmEntry = path.resolve(releaseDest, 'fesm2022/alauda-ui.mjs'); + const esmEntryContent = await fs.readFile(esmEntry, 'utf-8'); + await fs.writeFile( + esmEntry, + esmEntryContent.replace( + "import dayjs from 'dayjs';", + "import dayjs_ from 'dayjs';\nconst dayjs = 'default' in dayjs_ ? dayjs_.default : dayjs_;", + ), + ); } const packagr = ngPackagr @@ -40,7 +52,7 @@ const packagr = ngPackagr if (watch) { packagr.watch().subscribe(() => { - copyResources(); + afterBuild(); if (!isDebug) { const src = path.resolve(__dirname, '../release'); @@ -50,6 +62,6 @@ if (watch) { } }); } else { - // eslint-disable-next-line unicorn/prefer-top-level-await - packagr.build().then(copyResources); + + packagr.build().then(afterBuild); } diff --git a/scripts/copy-resources.js b/scripts/copy-resources.js deleted file mode 100644 index c529ac209..000000000 --- a/scripts/copy-resources.js +++ /dev/null @@ -1,23 +0,0 @@ -const gulp = require('gulp'); -const sass = require('gulp-dart-sass'); - -const isDebug = process.argv[2] === '--debug'; - -const debugNgPackage = '../ng-package.debug.json'; - -const dest = (isDebug ? require(debugNgPackage).dest : 'release') + '/theme'; - -gulp - .src([ - 'src/theme/_base-var.scss', - 'src/theme/_pattern.scss', - 'src/theme/_var.scss', - 'src/theme/_theme-preset.scss', - 'src/theme/_mixin.scss', - ]) - .pipe(gulp.dest(dest)); - -gulp - .src('src/theme/style.scss') - .pipe(sass().on('error', sass.logError)) - .pipe(gulp.dest(dest));