diff --git a/packages/core/package.json b/packages/core/package.json index aa597ea58..95ff6bd49 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -43,7 +43,9 @@ "name": "IntlifyCore", "formats": [ "mjs", + "mjs-node", "mjs-runtime", + "mjs-node-runtime", "browser", "browser-runtime", "cjs", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index d7f7450ad..9b2fd7a49 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -8,9 +8,14 @@ import { fallbackWithLocaleChain } from '@intlify/core-base' import { initFeatureFlags } from '../../core-base/src/misc' +import { getGlobalThis } from '@intlify/shared' if (__ESM_BUNDLER__ && !__TEST__) { initFeatureFlags() + if (__NODE_JS__) { + // avoid Node.js CSP for Function() + getGlobalThis().__INTLIFY_JIT_COMPILATION__ = true + } } // register message compiler at @intlify/core diff --git a/packages/petite-vue-i18n/package.json b/packages/petite-vue-i18n/package.json index 2fd903f58..6c0109f4a 100644 --- a/packages/petite-vue-i18n/package.json +++ b/packages/petite-vue-i18n/package.json @@ -52,7 +52,9 @@ "name": "PetiteVueI18n", "formats": [ "mjs", + "mjs-node", "mjs-runtime", + "mjs-node-runtime", "browser", "browser-runtime", "cjs", @@ -68,8 +70,8 @@ "node": { "import": { "production": "./dist/petite-vue-i18n.node.mjs", - "development": "./dist/petite-vue-i18n.mjs", - "default": "./dist/petite-vue-i18n.mjs" + "development": "./dist/petite-vue-i18n.node.mjs", + "default": "./dist/petite-vue-i18n.node.mjs" }, "require": { "production": "./dist/petite-vue-i18n.prod.cjs", diff --git a/packages/vue-i18n/package.json b/packages/vue-i18n/package.json index afc2e6ded..3923ef558 100644 --- a/packages/vue-i18n/package.json +++ b/packages/vue-i18n/package.json @@ -52,7 +52,9 @@ "name": "VueI18n", "formats": [ "mjs", + "mjs-node", "mjs-runtime", + "mjs-node-runtime", "browser", "browser-runtime", "cjs", @@ -68,8 +70,8 @@ "node": { "import": { "production": "./dist/vue-i18n.node.mjs", - "development": "./dist/vue-i18n.mjs", - "default": "./dist/vue-i18n.mjs" + "development": "./dist/vue-i18n.node.mjs", + "default": "./dist/vue-i18n.node.mjs" }, "require": { "production": "./dist/vue-i18n.prod.cjs", diff --git a/rollup.config.mjs b/rollup.config.mjs index ad750a26f..bf6e200e3 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -52,16 +52,6 @@ const outputConfigs = { file: `dist/${name}.esm-browser.js`, format: `es` }, - /* - 'esm-bundler': { - file: `dist/${name}.esm-bundler.mjs`, - format: `es` - }, - 'esm-browser': { - file: `dist/${name}.esm-browser.mjs`, - format: `es` - }, - */ cjs: { // file: `dist/${name}.cjs.js`, file: `dist/${name}.cjs`, @@ -76,20 +66,14 @@ const outputConfigs = { file: `dist/${name}.runtime.mjs`, format: `es` }, - 'browser-runtime': { - file: `dist/${name}.runtime.esm-browser.js`, - format: 'es' - }, - /* - 'esm-bundler-runtime': { - file: `dist/${name}.runtime.esm-bundler.mjs`, + 'mjs-node-runtime': { + file: `dist/${name}.runtime.node.mjs`, format: `es` }, - 'esm-browser-runtime': { - file: `dist/${name}.runtime.esm-browser.mjs`, + 'browser-runtime': { + file: `dist/${name}.runtime.esm-browser.js`, format: 'es' }, - */ 'global-runtime': { file: `dist/${name}.runtime.global.js`, format: 'iife' @@ -216,6 +200,7 @@ function createConfig(format, _output, plugins = []) { }), tsPlugin, createReplacePlugin( + name, isProductionBuild, isBundlerESMBuild, isBrowserESMBuild, @@ -243,6 +228,7 @@ function createConfig(format, _output, plugins = []) { await fs.writeFile(resolve(`dist/${stub}`), contents) console.log(`created stub ${pc.bold(`dist/${stub}`)}`) + /* // add the node specific version if (format === 'mjs' || format === 'mjs-runtime') { // NOTE: @@ -271,6 +257,7 @@ function createConfig(format, _output, plugins = []) { console.log(`created stub ${pc.bold(outfile)}`) } } + */ } } ], @@ -287,6 +274,7 @@ function createConfig(format, _output, plugins = []) { } function createReplacePlugin( + name, isProduction, isBundlerESMBuild, isBrowserESMBuild, @@ -300,11 +288,14 @@ function createReplacePlugin( const replacements = { __COMMIT__: `"${process.env.COMMIT}"`, __VERSION__: `'${masterVersion}'`, - __DEV__: isBundlerESMBuild - ? // preserve to be handled by bundlers - `(process.env.NODE_ENV !== 'production')` - : // hard coded dev/prod builds - !isProduction, + __DEV__: + ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild + ? 'false' // tree-shake devtools + : isBundlerESMBuild + ? // preserve to be handled by bundlers + `(process.env.NODE_ENV !== 'production')` + : // hard coded dev/prod builds + !isProduction, // this is only used during Vue's internal tests __TEST__: `false`, // If the build is expected to run directly in the browser (global / esm builds) @@ -327,9 +318,12 @@ function createReplacePlugin( __FEATURE_LEGACY_API__: isBundlerESMBuild ? `__VUE_I18N_LEGACY_API__` : `true`, - __FEATURE_PROD_VUE_DEVTOOLS__: isBundlerESMBuild - ? `__VUE_PROD_DEVTOOLS__` - : `false`, + __FEATURE_PROD_VUE_DEVTOOLS__: + ['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild + ? 'false' // tree-shake devtools + : isBundlerESMBuild + ? `__VUE_PROD_DEVTOOLS__` + : `false`, __FEATURE_PROD_INTLIFY_DEVTOOLS__: isBundlerESMBuild ? `__INTLIFY_PROD_DEVTOOLS__` : `false`,