Skip to content

Commit 5ff1b1d

Browse files
authored
fix: Not load devtools on Node.js (#1843)
ref: #1841
1 parent e9c2e6c commit 5ff1b1d

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

packages/core/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
"name": "IntlifyCore",
4444
"formats": [
4545
"mjs",
46+
"mjs-node",
4647
"mjs-runtime",
48+
"mjs-node-runtime",
4749
"browser",
4850
"browser-runtime",
4951
"cjs",

packages/core/src/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ import {
88
fallbackWithLocaleChain
99
} from '@intlify/core-base'
1010
import { initFeatureFlags } from '../../core-base/src/misc'
11+
import { getGlobalThis } from '@intlify/shared'
1112

1213
if (__ESM_BUNDLER__ && !__TEST__) {
1314
initFeatureFlags()
15+
if (__NODE_JS__) {
16+
// avoid Node.js CSP for Function()
17+
getGlobalThis().__INTLIFY_JIT_COMPILATION__ = true
18+
}
1419
}
1520

1621
// register message compiler at @intlify/core

packages/petite-vue-i18n/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"name": "PetiteVueI18n",
5353
"formats": [
5454
"mjs",
55+
"mjs-node",
5556
"mjs-runtime",
57+
"mjs-node-runtime",
5658
"browser",
5759
"browser-runtime",
5860
"cjs",
@@ -68,8 +70,8 @@
6870
"node": {
6971
"import": {
7072
"production": "./dist/petite-vue-i18n.node.mjs",
71-
"development": "./dist/petite-vue-i18n.mjs",
72-
"default": "./dist/petite-vue-i18n.mjs"
73+
"development": "./dist/petite-vue-i18n.node.mjs",
74+
"default": "./dist/petite-vue-i18n.node.mjs"
7375
},
7476
"require": {
7577
"production": "./dist/petite-vue-i18n.prod.cjs",

packages/vue-i18n/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"name": "VueI18n",
5353
"formats": [
5454
"mjs",
55+
"mjs-node",
5556
"mjs-runtime",
57+
"mjs-node-runtime",
5658
"browser",
5759
"browser-runtime",
5860
"cjs",
@@ -68,8 +70,8 @@
6870
"node": {
6971
"import": {
7072
"production": "./dist/vue-i18n.node.mjs",
71-
"development": "./dist/vue-i18n.mjs",
72-
"default": "./dist/vue-i18n.mjs"
73+
"development": "./dist/vue-i18n.node.mjs",
74+
"default": "./dist/vue-i18n.node.mjs"
7375
},
7476
"require": {
7577
"production": "./dist/vue-i18n.prod.cjs",

rollup.config.mjs

+22-28
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ const outputConfigs = {
5252
file: `dist/${name}.esm-browser.js`,
5353
format: `es`
5454
},
55-
/*
56-
'esm-bundler': {
57-
file: `dist/${name}.esm-bundler.mjs`,
58-
format: `es`
59-
},
60-
'esm-browser': {
61-
file: `dist/${name}.esm-browser.mjs`,
62-
format: `es`
63-
},
64-
*/
6555
cjs: {
6656
// file: `dist/${name}.cjs.js`,
6757
file: `dist/${name}.cjs`,
@@ -76,20 +66,14 @@ const outputConfigs = {
7666
file: `dist/${name}.runtime.mjs`,
7767
format: `es`
7868
},
79-
'browser-runtime': {
80-
file: `dist/${name}.runtime.esm-browser.js`,
81-
format: 'es'
82-
},
83-
/*
84-
'esm-bundler-runtime': {
85-
file: `dist/${name}.runtime.esm-bundler.mjs`,
69+
'mjs-node-runtime': {
70+
file: `dist/${name}.runtime.node.mjs`,
8671
format: `es`
8772
},
88-
'esm-browser-runtime': {
89-
file: `dist/${name}.runtime.esm-browser.mjs`,
73+
'browser-runtime': {
74+
file: `dist/${name}.runtime.esm-browser.js`,
9075
format: 'es'
9176
},
92-
*/
9377
'global-runtime': {
9478
file: `dist/${name}.runtime.global.js`,
9579
format: 'iife'
@@ -216,6 +200,7 @@ function createConfig(format, _output, plugins = []) {
216200
}),
217201
tsPlugin,
218202
createReplacePlugin(
203+
name,
219204
isProductionBuild,
220205
isBundlerESMBuild,
221206
isBrowserESMBuild,
@@ -243,6 +228,7 @@ function createConfig(format, _output, plugins = []) {
243228
await fs.writeFile(resolve(`dist/${stub}`), contents)
244229
console.log(`created stub ${pc.bold(`dist/${stub}`)}`)
245230

231+
/*
246232
// add the node specific version
247233
if (format === 'mjs' || format === 'mjs-runtime') {
248234
// NOTE:
@@ -271,6 +257,7 @@ function createConfig(format, _output, plugins = []) {
271257
console.log(`created stub ${pc.bold(outfile)}`)
272258
}
273259
}
260+
*/
274261
}
275262
}
276263
],
@@ -287,6 +274,7 @@ function createConfig(format, _output, plugins = []) {
287274
}
288275

289276
function createReplacePlugin(
277+
name,
290278
isProduction,
291279
isBundlerESMBuild,
292280
isBrowserESMBuild,
@@ -300,11 +288,14 @@ function createReplacePlugin(
300288
const replacements = {
301289
__COMMIT__: `"${process.env.COMMIT}"`,
302290
__VERSION__: `'${masterVersion}'`,
303-
__DEV__: isBundlerESMBuild
304-
? // preserve to be handled by bundlers
305-
`(process.env.NODE_ENV !== 'production')`
306-
: // hard coded dev/prod builds
307-
!isProduction,
291+
__DEV__:
292+
['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild
293+
? 'false' // tree-shake devtools
294+
: isBundlerESMBuild
295+
? // preserve to be handled by bundlers
296+
`(process.env.NODE_ENV !== 'production')`
297+
: // hard coded dev/prod builds
298+
!isProduction,
308299
// this is only used during Vue's internal tests
309300
__TEST__: `false`,
310301
// If the build is expected to run directly in the browser (global / esm builds)
@@ -327,9 +318,12 @@ function createReplacePlugin(
327318
__FEATURE_LEGACY_API__: isBundlerESMBuild
328319
? `__VUE_I18N_LEGACY_API__`
329320
: `true`,
330-
__FEATURE_PROD_VUE_DEVTOOLS__: isBundlerESMBuild
331-
? `__VUE_PROD_DEVTOOLS__`
332-
: `false`,
321+
__FEATURE_PROD_VUE_DEVTOOLS__:
322+
['vue-i18n', 'petite-vue-i18n'].includes(name) && isNodeBuild
323+
? 'false' // tree-shake devtools
324+
: isBundlerESMBuild
325+
? `__VUE_PROD_DEVTOOLS__`
326+
: `false`,
333327
__FEATURE_PROD_INTLIFY_DEVTOOLS__: isBundlerESMBuild
334328
? `__INTLIFY_PROD_DEVTOOLS__`
335329
: `false`,

0 commit comments

Comments
 (0)