From ccbbe641dd4fc0975d9597cee394a3c4d797510c Mon Sep 17 00:00:00 2001 From: Welly Shen Date: Sun, 8 Nov 2020 12:53:41 +0800 Subject: [PATCH] fix: correct UMD format --- .changeset/happy-singers-allow.md | 5 +++++ rollup/config.js | 3 +++ rollup/createConfig.js | 10 +++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .changeset/happy-singers-allow.md diff --git a/.changeset/happy-singers-allow.md b/.changeset/happy-singers-allow.md new file mode 100644 index 00000000..36a3be76 --- /dev/null +++ b/.changeset/happy-singers-allow.md @@ -0,0 +1,5 @@ +--- +"react-cool-form": patch +--- + +fix: correct UMD format diff --git a/rollup/config.js b/rollup/config.js index 2149f4ea..10114d38 100644 --- a/rollup/config.js +++ b/rollup/config.js @@ -2,6 +2,7 @@ import createConfig from "./createConfig"; const isDev = process.env.BUILD !== "production"; const name = "index"; +const umdName = "ReactCoolForm"; const options = [ { name, @@ -19,11 +20,13 @@ const options = [ }, { name, + umdName, format: "umd", env: "development", }, { name, + umdName, format: "umd", env: "production", }, diff --git a/rollup/createConfig.js b/rollup/createConfig.js index f635b82a..f61cfe26 100644 --- a/rollup/createConfig.js +++ b/rollup/createConfig.js @@ -18,7 +18,7 @@ const makeExternalPredicate = (external) => ? () => false : (id) => new RegExp(`^(${external.join("|")})($|/)`).test(id); -export default ({ name, format, env, size }) => { +export default ({ name, umdName, format, env, size }) => { const extensions = [".ts"]; const isUmd = format === "umd"; const isProd = env === "production"; @@ -31,7 +31,7 @@ export default ({ name, format, env, size }) => { output: { file: `dist/${fileName}`, format, - name: pkg.name, + name: umdName, sourcemap: true, globals: { react: "React" }, exports: "named", @@ -44,7 +44,11 @@ export default ({ name, format, env, size }) => { plugins: [ [ "@babel/plugin-transform-runtime", - { version: babelRuntimeVersion, helpers: !isUmd }, + { + version: babelRuntimeVersion, + useESModules: format !== "cjs", + helpers: !isUmd, + }, ], ], babelHelpers: isUmd ? "bundled" : "runtime",