From 197d476258cb8545eb794e8b8c8a2d92bdccca2a Mon Sep 17 00:00:00 2001 From: daishi Date: Thu, 27 Oct 2022 23:31:47 +0900 Subject: [PATCH] fix(build): no import.meta for "module" condition --- rollup.config.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/rollup.config.js b/rollup.config.js index 3963e02b..edd72e28 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -52,10 +52,7 @@ function createDeclarationConfig(input, output) { function createESMConfig(input, output) { return { input, - output: [ - { file: `${output}.js`, format: 'esm' }, - { file: `${output}.mjs`, format: 'esm' }, - ], + output: { file: output, format: 'esm' }, external, plugins: [ alias({ @@ -66,7 +63,9 @@ function createESMConfig(input, output) { }), resolve({ extensions }), replace({ - __DEV__: '(import.meta.env&&import.meta.env.MODE)!=="production"', + __DEV__: output.endsWith('.mjs') + ? '((import.meta.env&&import.meta.env.MODE)!=="production")' + : '(process.env.NODE_ENV!=="production")', // a workround for #410 'use-sync-external-store/shim': 'use-sync-external-store/shim/index.js', delimiters: ['\\b', '\\b(?!(\\.|/))'], @@ -80,7 +79,7 @@ function createESMConfig(input, output) { function createCommonJSConfig(input, output) { return { input, - output: { file: `${output}.js`, format: 'cjs', exports: 'named' }, + output: { file: `${output}.js`, format: 'cjs' }, external, plugins: [ alias({ @@ -91,7 +90,7 @@ function createCommonJSConfig(input, output) { }), resolve({ extensions }), replace({ - __DEV__: 'process.env.NODE_ENV!=="production"', + __DEV__: '(process.env.NODE_ENV!=="production")', preventAssignment: true, }), babelPlugin(getBabelOptions({ ie: 11 })), @@ -106,7 +105,6 @@ function createUMDConfig(input, output, env) { output: { file: `${output}.${env}.js`, format: 'umd', - exports: 'named', name: c === 'index' ? 'valtio' @@ -141,7 +139,6 @@ function createSystemConfig(input, output, env) { output: { file: `${output}.${env}.js`, format: 'system', - exports: 'named', }, external, plugins: [ @@ -171,7 +168,8 @@ module.exports = function (args) { return [ ...(c === 'index' ? [createDeclarationConfig(`src/${c}.ts`, 'dist')] : []), createCommonJSConfig(`src/${c}.ts`, `dist/${c}`), - createESMConfig(`src/${c}.ts`, `dist/esm/${c}`), + createESMConfig(`src/${c}.ts`, `dist/esm/${c}.js`), + createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`), createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'development'), createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'production'), createSystemConfig(`src/${c}.ts`, `dist/system/${c}`, 'development'),