Skip to content

Commit 1b13904

Browse files
authored
feat: support node esm for message compiler (#1460)
1 parent 96fabe1 commit 1b13904

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

packages/message-compiler/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"name": "IntlifyMessageCompiler",
4444
"formats": [
4545
"mjs",
46+
"mjs-node",
4647
"browser",
4748
"cjs",
4849
"global"
@@ -56,9 +57,9 @@
5657
"browser": "./dist/message-compiler.esm-browser.js",
5758
"node": {
5859
"import": {
59-
"production": "./dist/message-compiler.prod.cjs",
60-
"development": "./dist/message-compiler.mjs",
61-
"default": "./dist/message-compiler.mjs"
60+
"production": "./dist/message-compiler.node.mjs",
61+
"development": "./dist/message-compiler.node.mjs",
62+
"default": "./dist/message-compiler.node.mjs"
6263
},
6364
"require": {
6465
"production": "./dist/message-compiler.prod.cjs",

packages/message-compiler/src/generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ function createCodeGenerator(
9090

9191
function push(code: string, node?: CodeGenNode): void {
9292
_context.code += code
93-
if (!__BROWSER__ && _context.map) {
93+
if (__NODE_JS__ && _context.map) {
9494
if (node && node.loc && node.loc !== LOCATION_STUB) {
9595
addMapping(node.loc.start, getMappingName(node))
9696
}
@@ -135,7 +135,7 @@ function createCodeGenerator(
135135
})
136136
}
137137

138-
if (!__BROWSER__ && location && sourceMap) {
138+
if (__NODE_JS__ && location && sourceMap) {
139139
_context.map = new SourceMapGenerator()
140140
_context.map!.setSourceContent(filename!, _context.source!)
141141
}

rollup.config.mjs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ const outputConfigs = {
4444
file: `dist/${name}.mjs`,
4545
format: `es`
4646
},
47+
'mjs-node': {
48+
file: `dist/${name}.node.mjs`,
49+
format: `es`
50+
},
4751
browser: {
4852
file: `dist/${name}.esm-browser.js`,
4953
format: `es`
@@ -326,39 +330,38 @@ function createReplacePlugin(
326330
: // hard coded dev/prod builds
327331
!isProduction,
328332
// this is only used during Vue's internal tests
329-
__TEST__: false,
333+
__TEST__: `false`,
330334
// If the build is expected to run directly in the browser (global / esm builds)
331-
__BROWSER__: isBrowserBuild,
332-
__GLOBAL__: isGlobalBuild,
335+
__BROWSER__: String(isBrowserBuild),
336+
__GLOBAL__: String(isGlobalBuild),
333337
// for runtime only
334-
__RUNTIME__: isRuntimeOnlyBuild,
338+
__RUNTIME__: String(isRuntimeOnlyBuild),
335339
// bundle filename
336340
__BUNDLE_FILENAME__: `'${bundleFilename}'`,
337-
__ESM_BUNDLER__: isBundlerESMBuild,
338-
__ESM_BROWSER__: isBrowserESMBuild,
341+
__ESM_BUNDLER__: String(isBundlerESMBuild),
342+
__ESM_BROWSER__: String(isBrowserESMBuild),
339343
// is targeting Node (SSR)?
340-
__NODE_JS__: isNodeBuild,
344+
__NODE_JS__: String(isNodeBuild),
341345
// for lite version
342-
__LITE__: isLite,
346+
__LITE__: String(isLite),
343347
// for bridge version
344-
__BRIDGE__: isBridge,
348+
__BRIDGE__: String(isBridge),
345349
// feature flags
346350
__FEATURE_FULL_INSTALL__: isBundlerESMBuild
347351
? `__VUE_I18N_FULL_INSTALL__`
348-
: true,
352+
: `true`,
349353
__FEATURE_LEGACY_API__: isBundlerESMBuild
350354
? `__VUE_I18N_LEGACY_API__`
351-
: true,
355+
: `true`,
352356
__FEATURE_PROD_VUE_DEVTOOLS__: isBundlerESMBuild
353357
? `__VUE_PROD_DEVTOOLS__`
354-
: false,
358+
: `false`,
355359
__FEATURE_PROD_INTLIFY_DEVTOOLS__: isBundlerESMBuild
356360
? `__INTLIFY_PROD_DEVTOOLS__`
357-
: false,
361+
: `false`,
358362
__FEATURE_JIT_COMPILATION__: isBundlerESMBuild
359363
? `__INTLIFY_JIT_COMPILATION__`
360-
: false,
361-
preventAssignment: false,
364+
: `false`,
362365
...(isProduction && isBrowserBuild
363366
? {
364367
'emitError(': `/*#__PURE__*/ emitError(`,
@@ -375,7 +378,7 @@ function createReplacePlugin(
375378
replacements[key] = process.env[key]
376379
}
377380
})
378-
return replace(replacements)
381+
return replace({ values: replacements, preventAssignment: true })
379382
}
380383

381384
function createProductionConfig(format) {

0 commit comments

Comments
 (0)