Skip to content

Commit 2c7b358

Browse files
authored
feat(core): optimize core package for node.js (#1530)
1 parent bf37081 commit 2c7b358

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

packages/core/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,19 @@ The intlify core module for i18n
3737
### For Node.js (Server-Side)
3838

3939
- **`core.cjs(.prod).js`**:
40+
- For CommonJS usage in Node.js
4041
- For use in Node.js via `require()`
4142
- If you bundle your app with webpack with `target: 'node'` and properly externalize `@intlify/core`, this is the build that will be loaded
4243
- The dev/prod files are pre-built, but the appropriate file is automatically required based on `process.env.NODE_ENV`
4344

45+
- **`core.node.mjs`**:
46+
- For ES Moudles usage in Node.js
47+
- For use in Node.js via `import`
48+
- The dev/prod files are pre-built, but the appropriate file is automatically required based on `process.env`<wbr/>`.NODE_ENV`
49+
50+
> NOTE: ES Modules will be the future of the Node.js module system. The `core.cjs(.prod).js` will be deprecated in the future. We recommend you would use `core.node.mjs`. 9.3+
51+
52+
4453
## :copyright: License
4554

4655
[MIT](http://opensource.org/licenses/MIT)

packages/core/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,20 @@
5454
"exports": {
5555
".": {
5656
"types": "./dist/core.d.ts",
57-
"import": "./dist/core.mjs",
58-
"browser": "./dist/core.esm-browser.js",
5957
"node": {
6058
"import": {
61-
"production": "./dist/core.prod.cjs",
62-
"development": "./dist/core.mjs",
63-
"default": "./dist/core.mjs"
59+
"production": "./dist/core.prod.node.mjs",
60+
"development": "./dist/core.node.mjs",
61+
"default": "./dist/core.node.mjs"
6462
},
6563
"require": {
6664
"production": "./dist/core.prod.cjs",
6765
"development": "./dist/core.cjs",
6866
"default": "./index.js"
6967
}
70-
}
68+
},
69+
"import": "./dist/core.mjs",
70+
"browser": "./dist/core.esm-browser.js"
7171
},
7272
"./dist/*": "./dist/*",
7373
"./package.json": "./package.json"

rollup.config.mjs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,22 +274,26 @@ function createConfig(format, _output, plugins = []) {
274274
console.log(`created stub ${pc.bold(`dist/${stub}`)}`)
275275

276276
// add the node specific version
277-
// NOTE:
278-
// https://github.com/vuejs/router/issues/1516
279-
// https://github.com/vuejs/router/commit/53f720622aa273e33c05517fa917cdcfbfba52bc
280-
if (
281-
format === 'mjs' &&
282-
(name === 'vue-i18n' ||
283-
name === 'vue-i18n-bridge' ||
284-
name === 'petite-vue-i18n')
285-
) {
286-
const outfile = `dist/${stub}`.replace('esm-bundler.js', 'node.mjs')
287-
await fs.writeFile(
288-
resolve(outfile),
289-
`global.__VUE_PROD_DEVTOOLS__ = false;\n` + contents
290-
)
291-
console.log(`created stub ${pc.bold(outfile)}`)
292-
}
277+
if (format === 'mjs') {
278+
// NOTE:
279+
// https://github.com/vuejs/router/issues/1516
280+
// https://github.com/vuejs/router/commit/53f720622aa273e33c05517fa917cdcfbfba52bc
281+
if (name === 'vue-i18n' || name === 'vue-i18n-bridge' || name === 'petite-vue-i18n') {
282+
const outfile = `dist/${stub}`.replace('esm-bundler.js', 'node.mjs')
283+
await fs.writeFile(
284+
resolve(outfile),
285+
`global.__VUE_PROD_DEVTOOLS__ = false;\n` + contents
286+
)
287+
console.log(`created stub ${pc.bold(outfile)}`)
288+
} else if(name === 'core') {
289+
const outfile = `dist/${stub}`.replace('esm-bundler.js', 'node.mjs')
290+
await fs.writeFile(
291+
resolve(outfile),
292+
`global.__VUE_PROD_DEVTOOLS__ = false;\nglobal.__INTLIFY_JIT_COMPILATION__ = true;\n` + contents
293+
)
294+
console.log(`created stub ${pc.bold(outfile)}`)
295+
}
296+
}
293297
}
294298
}
295299
],

0 commit comments

Comments
 (0)