Skip to content

Commit

Permalink
fix: Not load devtools on Node.js (#1843)
Browse files Browse the repository at this point in the history
ref: #1841
  • Loading branch information
kazupon committed May 7, 2024
1 parent e9c2e6c commit 5ff1b1d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 32 deletions.
2 changes: 2 additions & 0 deletions packages/core/package.json
Expand Up @@ -43,7 +43,9 @@
"name": "IntlifyCore",
"formats": [
"mjs",
"mjs-node",
"mjs-runtime",
"mjs-node-runtime",
"browser",
"browser-runtime",
"cjs",
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/index.ts
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions packages/petite-vue-i18n/package.json
Expand Up @@ -52,7 +52,9 @@
"name": "PetiteVueI18n",
"formats": [
"mjs",
"mjs-node",
"mjs-runtime",
"mjs-node-runtime",
"browser",
"browser-runtime",
"cjs",
Expand All @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions packages/vue-i18n/package.json
Expand Up @@ -52,7 +52,9 @@
"name": "VueI18n",
"formats": [
"mjs",
"mjs-node",
"mjs-runtime",
"mjs-node-runtime",
"browser",
"browser-runtime",
"cjs",
Expand All @@ -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",
Expand Down
50 changes: 22 additions & 28 deletions rollup.config.mjs
Expand Up @@ -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`,
Expand All @@ -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'
Expand Down Expand Up @@ -216,6 +200,7 @@ function createConfig(format, _output, plugins = []) {
}),
tsPlugin,
createReplacePlugin(
name,
isProductionBuild,
isBundlerESMBuild,
isBrowserESMBuild,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -271,6 +257,7 @@ function createConfig(format, _output, plugins = []) {
console.log(`created stub ${pc.bold(outfile)}`)
}
}
*/
}
}
],
Expand All @@ -287,6 +274,7 @@ function createConfig(format, _output, plugins = []) {
}

function createReplacePlugin(
name,
isProduction,
isBundlerESMBuild,
isBrowserESMBuild,
Expand All @@ -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)
Expand All @@ -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`,
Expand Down

0 comments on commit 5ff1b1d

Please sign in to comment.