Skip to content

Commit

Permalink
feat(core): optimize core package for node.js (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Sep 8, 2023
1 parent bf37081 commit 2c7b358
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
9 changes: 9 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@ The intlify core module for i18n
### For Node.js (Server-Side)

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

- **`core.node.mjs`**:
- For ES Moudles usage in Node.js
- For use in Node.js via `import`
- The dev/prod files are pre-built, but the appropriate file is automatically required based on `process.env`<wbr/>`.NODE_ENV`

> 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+

## :copyright: License

[MIT](http://opensource.org/licenses/MIT)
12 changes: 6 additions & 6 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@
"exports": {
".": {
"types": "./dist/core.d.ts",
"import": "./dist/core.mjs",
"browser": "./dist/core.esm-browser.js",
"node": {
"import": {
"production": "./dist/core.prod.cjs",
"development": "./dist/core.mjs",
"default": "./dist/core.mjs"
"production": "./dist/core.prod.node.mjs",
"development": "./dist/core.node.mjs",
"default": "./dist/core.node.mjs"
},
"require": {
"production": "./dist/core.prod.cjs",
"development": "./dist/core.cjs",
"default": "./index.js"
}
}
},
"import": "./dist/core.mjs",
"browser": "./dist/core.esm-browser.js"
},
"./dist/*": "./dist/*",
"./package.json": "./package.json"
Expand Down
36 changes: 20 additions & 16 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,26 @@ function createConfig(format, _output, plugins = []) {
console.log(`created stub ${pc.bold(`dist/${stub}`)}`)

// add the node specific version
// NOTE:
// https://github.com/vuejs/router/issues/1516
// https://github.com/vuejs/router/commit/53f720622aa273e33c05517fa917cdcfbfba52bc
if (
format === 'mjs' &&
(name === 'vue-i18n' ||
name === 'vue-i18n-bridge' ||
name === 'petite-vue-i18n')
) {
const outfile = `dist/${stub}`.replace('esm-bundler.js', 'node.mjs')
await fs.writeFile(
resolve(outfile),
`global.__VUE_PROD_DEVTOOLS__ = false;\n` + contents
)
console.log(`created stub ${pc.bold(outfile)}`)
}
if (format === 'mjs') {
// NOTE:
// https://github.com/vuejs/router/issues/1516
// https://github.com/vuejs/router/commit/53f720622aa273e33c05517fa917cdcfbfba52bc
if (name === 'vue-i18n' || name === 'vue-i18n-bridge' || name === 'petite-vue-i18n') {
const outfile = `dist/${stub}`.replace('esm-bundler.js', 'node.mjs')
await fs.writeFile(
resolve(outfile),
`global.__VUE_PROD_DEVTOOLS__ = false;\n` + contents
)
console.log(`created stub ${pc.bold(outfile)}`)
} else if(name === 'core') {
const outfile = `dist/${stub}`.replace('esm-bundler.js', 'node.mjs')
await fs.writeFile(
resolve(outfile),
`global.__VUE_PROD_DEVTOOLS__ = false;\nglobal.__INTLIFY_JIT_COMPILATION__ = true;\n` + contents
)
console.log(`created stub ${pc.bold(outfile)}`)
}
}
}
}
],
Expand Down

0 comments on commit 2c7b358

Please sign in to comment.