From b2d9ca33508c3b92fdd4912e007a63d2fc799bcb Mon Sep 17 00:00:00 2001 From: Dohyeong Date: Thu, 7 Jan 2021 20:26:39 +0900 Subject: [PATCH] =?UTF-8?q?es=20subpath=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- babel.config.cjs | 5 +++++ package.json | 10 ++++++---- scripts/transform_import_fxjs.cjs | 11 +++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 scripts/transform_import_fxjs.cjs diff --git a/babel.config.cjs b/babel.config.cjs index 02408f3..fa3fb45 100644 --- a/babel.config.cjs +++ b/babel.config.cjs @@ -14,12 +14,17 @@ module.exports = (api) => { ], ]; + if (BABEL_ENV === "mjs") { + plugins.push("./scripts/transform_import_fxjs.cjs"); + } + return { presets: [ [ "@babel/preset-env", { targets, + modules: BABEL_ENV === "mjs" ? false : "auto", }, ], ], diff --git a/package.json b/package.json index e8505f9..dcab2a3 100644 --- a/package.json +++ b/package.json @@ -8,16 +8,18 @@ "type": "module", "scripts": { "generate:index": "node scripts/index_generator.js", - "copy-files": "rm src/index.js && mv src/_internal ./ && mv src/*.js ./ && rm -rf src", + "copy-es-files": "mkdir es && cp -r ./src/* ./es", "build:modern": "NODE_ENV=production BABEL_ENV=modern webpack", "build:legacy": "NODE_ENV=production BABEL_ENV=legacy webpack", - "build": "npm run generate:index && npm run build:modern && npm run build:legacy && npm run copy-files", + "transpile": "BABEL_ENV=mjs babel src/ --out-dir ./", + "build": "npm run build:modern && npm run build:legacy && npm run generate:index && mv -f ./index.js src/ && npm run copy-es-files && npm run transpile && rm -rf src/", "deploy": "np --no-publish --no-tests && npm run build && npm publish", "test:server": "node ./test/server.cjs" }, "files": [ - "dist", - "_internal", + "dist/", + "_internal/", + "es/", "*.js" ], "repository": { diff --git a/scripts/transform_import_fxjs.cjs b/scripts/transform_import_fxjs.cjs new file mode 100644 index 0000000..0fb9e3a --- /dev/null +++ b/scripts/transform_import_fxjs.cjs @@ -0,0 +1,11 @@ +module.exports = () => ({ + visitor: { + ImportDeclaration(path, state) { + const { source } = path.node; + const { value } = source; + if (value.startsWith("fxjs/es")) { + source.value = source.value.replace('fxjs/es', 'fxjs'); + } + }, + }, +});