Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: use cjs/mjs extensions for cjs/esm builds #4814

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/compiler-core/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/compiler-core.prod.cjs')
} else {
module.exports = require('./dist/compiler-core.cjs')
}
7 changes: 0 additions & 7 deletions packages/compiler-core/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/compiler-core/package.json
Expand Up @@ -2,11 +2,11 @@
"name": "@vue/compiler-core",
"version": "3.2.20",
"description": "@vue/compiler-core",
"main": "index.js",
"module": "dist/compiler-core.esm-bundler.js",
"main": "index.cjs",
"module": "dist/compiler-core.esm-bundler.mjs",
"types": "dist/compiler-core.d.ts",
"files": [
"index.js",
"index.cjs",
"dist"
],
"buildOptions": {
Expand Down
7 changes: 7 additions & 0 deletions packages/compiler-dom/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/compiler-dom.prod.cjs')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest adding conditional exports at the same time so instead of process.env workaround, we can use import conditions to use dev or prod build

} else {
module.exports = require('./dist/compiler-dom.cjs')
}
7 changes: 0 additions & 7 deletions packages/compiler-dom/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/compiler-dom/package.json
Expand Up @@ -2,13 +2,13 @@
"name": "@vue/compiler-dom",
"version": "3.2.20",
"description": "@vue/compiler-dom",
"main": "index.js",
"module": "dist/compiler-dom.esm-bundler.js",
"main": "index.cjs",
"module": "dist/compiler-dom.esm-bundler.mjs",
"types": "dist/compiler-dom.d.ts",
"unpkg": "dist/compiler-dom.global.js",
"jsdelivr": "dist/compiler-dom.global.js",
"files": [
"index.js",
"index.cjs",
"dist"
],
"sideEffects": false,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-sfc/package.json
Expand Up @@ -2,8 +2,8 @@
"name": "@vue/compiler-sfc",
"version": "3.2.20",
"description": "@vue/compiler-sfc",
"main": "dist/compiler-sfc.cjs.js",
"module": "dist/compiler-sfc.esm-browser.js",
"main": "dist/compiler-sfc.cjs",
"module": "dist/compiler-sfc.esm-browser.mjs",
"types": "dist/compiler-sfc.d.ts",
"files": [
"dist"
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-ssr/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@vue/compiler-ssr",
"version": "3.2.20",
"description": "@vue/compiler-ssr",
"main": "dist/compiler-ssr.cjs.js",
"main": "dist/compiler-ssr.cjs",
"types": "dist/compiler-ssr.d.ts",
"files": [
"dist"
Expand Down
7 changes: 7 additions & 0 deletions packages/reactivity/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/reactivity.prod.cjs')
} else {
module.exports = require('./dist/reactivity.cjs')
}
7 changes: 0 additions & 7 deletions packages/reactivity/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/reactivity/package.json
Expand Up @@ -2,13 +2,13 @@
"name": "@vue/reactivity",
"version": "3.2.20",
"description": "@vue/reactivity",
"main": "index.js",
"module": "dist/reactivity.esm-bundler.js",
"main": "index.cjs",
"module": "dist/reactivity.esm-bundler.mjs",
"types": "dist/reactivity.d.ts",
"unpkg": "dist/reactivity.global.js",
"jsdelivr": "dist/reactivity.global.js",
"files": [
"index.js",
"index.cjs",
"dist"
],
"sideEffects": false,
Expand Down
2 changes: 1 addition & 1 deletion packages/ref-transform/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "@vue/ref-transform",
"version": "3.2.20",
"description": "@vue/ref-transform",
"main": "dist/ref-transform.cjs.js",
"main": "dist/ref-transform.cjs",
"files": [
"dist"
],
Expand Down
7 changes: 7 additions & 0 deletions packages/runtime-core/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/runtime-core.prod.cjs')
} else {
module.exports = require('./dist/runtime-core.cjs')
}
7 changes: 0 additions & 7 deletions packages/runtime-core/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/runtime-core/package.json
Expand Up @@ -2,11 +2,11 @@
"name": "@vue/runtime-core",
"version": "3.2.20",
"description": "@vue/runtime-core",
"main": "index.js",
"module": "dist/runtime-core.esm-bundler.js",
"main": "index.cjs",
"module": "dist/runtime-core.esm-bundler.mjs",
"types": "dist/runtime-core.d.ts",
"files": [
"index.js",
"index.cjs",
"dist"
],
"buildOptions": {
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/component.ts
Expand Up @@ -820,9 +820,9 @@ export function finishComponentSetup(
`Component provided template option but ` +
`runtime compilation is not supported in this build of Vue.` +
(__ESM_BUNDLER__
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.js".`
? ` Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.mjs".`
: __ESM_BROWSER__
? ` Use "vue.esm-browser.js" instead.`
? ` Use "vue.esm-browser.mjs" instead.`
: __GLOBAL__
? ` Use "vue.global.js" instead.`
: ``) /* should not happen */
Expand Down
7 changes: 7 additions & 0 deletions packages/runtime-dom/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/runtime-dom.prod.cjs')
} else {
module.exports = require('./dist/runtime-dom.cjs')
}
7 changes: 0 additions & 7 deletions packages/runtime-dom/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/runtime-dom/package.json
Expand Up @@ -2,12 +2,12 @@
"name": "@vue/runtime-dom",
"version": "3.2.20",
"description": "@vue/runtime-dom",
"main": "index.js",
"module": "dist/runtime-dom.esm-bundler.js",
"main": "index.cjs",
"module": "dist/runtime-dom.esm-bundler.mjs",
"types": "dist/runtime-dom.d.ts",
"unpkg": "dist/runtime-dom.global.js",
"files": [
"index.js",
"index.cjs",
"dist"
],
"sideEffects": false,
Expand Down
7 changes: 7 additions & 0 deletions packages/runtime-test/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/runtime-test.prod.cjs')
} else {
module.exports = require('./dist/runtime-test.cjs')
}
7 changes: 0 additions & 7 deletions packages/runtime-test/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/runtime-test/package.json
Expand Up @@ -3,11 +3,11 @@
"version": "3.2.20",
"description": "@vue/runtime-test",
"private": true,
"main": "index.js",
"module": "dist/runtime-test.esm-bundler.js",
"main": "index.cjs",
"module": "dist/runtime-test.esm-bundler.mjs",
"types": "dist/runtime-test.d.ts",
"files": [
"index.js",
"index.cjs",
"dist"
],
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions packages/server-renderer/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/server-renderer.prod.cjs')
} else {
module.exports = require('./dist/server-renderer.cjs')
}
7 changes: 0 additions & 7 deletions packages/server-renderer/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/server-renderer/package.json
Expand Up @@ -2,11 +2,11 @@
"name": "@vue/server-renderer",
"version": "3.2.20",
"description": "@vue/server-renderer",
"main": "index.js",
"module": "dist/server-renderer.esm-bundler.js",
"main": "index.cjs",
"module": "dist/server-renderer.esm-bundler.mjs",
"types": "dist/server-renderer.d.ts",
"files": [
"index.js",
"index.cjs",
"dist"
],
"buildOptions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sfc-playground/src/App.vue
Expand Up @@ -12,7 +12,7 @@ setVH()
const store = new ReplStore({
serializedState: location.hash.slice(1),
defaultVueRuntimeURL: import.meta.env.PROD
? `${location.origin}/vue.runtime.esm-browser.js`
? `${location.origin}/vue.runtime.esm-browser.mjs`
: `${location.origin}/src/vue-dev-proxy`
})

Expand Down
6 changes: 3 additions & 3 deletions packages/sfc-playground/vite.config.ts
Expand Up @@ -23,17 +23,17 @@ function copyVuePlugin(): Plugin {
generateBundle() {
const filePath = path.resolve(
__dirname,
'../vue/dist/vue.runtime.esm-browser.js'
'../vue/dist/vue.runtime.esm-browser.mjs'
)
if (!fs.existsSync(filePath)) {
throw new Error(
`vue.runtime.esm-browser.js not built. ` +
`vue.runtime.esm-browser.mjs not built. ` +
`Run "nr build vue -f esm-browser" first.`
)
}
this.emitFile({
type: 'asset',
fileName: 'vue.runtime.esm-browser.js',
fileName: 'vue.runtime.esm-browser.mjs',
source: fs.readFileSync(filePath, 'utf-8')
})
}
Expand Down
7 changes: 7 additions & 0 deletions packages/shared/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/shared.prod.cjs')
} else {
module.exports = require('./dist/shared.cjs')
}
7 changes: 0 additions & 7 deletions packages/shared/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/shared/package.json
Expand Up @@ -2,11 +2,11 @@
"name": "@vue/shared",
"version": "3.2.20",
"description": "internal utils shared across @vue packages",
"main": "index.js",
"module": "dist/shared.esm-bundler.js",
"main": "index.cjs",
"module": "dist/shared.esm-bundler.mjs",
"types": "dist/shared.d.ts",
"files": [
"index.js",
"index.cjs",
"dist"
],
"buildOptions": {
Expand Down
7 changes: 7 additions & 0 deletions packages/vue-compat/index.cjs
@@ -0,0 +1,7 @@
'use strict'

if (process.env.NODE_ENV === 'production') {
module.exports = require('./dist/vue.prod.cjs')
} else {
module.exports = require('./dist/vue.cjs')
}
7 changes: 0 additions & 7 deletions packages/vue-compat/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions packages/vue-compat/package.json
Expand Up @@ -2,12 +2,12 @@
"name": "@vue/compat",
"version": "3.2.20",
"description": "Vue 3 compatibility build for Vue 2",
"main": "index.js",
"module": "dist/vue.runtime.esm-bundler.js",
"main": "index.cjs",
"module": "dist/vue.runtime.esm-bundler.mjs",
"unpkg": "dist/vue.global.js",
"jsdelivr": "dist/vue.global.js",
"files": [
"index.js",
"index.cjs",
"dist"
],
"buildOptions": {
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-compat/src/createCompatVue.ts
@@ -1,5 +1,5 @@
// This entry exports the runtime only, and is built as
// `dist/vue.esm-bundler.js` which is used by default for bundlers.
// `dist/vue.esm-bundler.mjs` which is used by default for bundlers.
import { initDev } from './dev'
import {
compatUtils,
Expand Down
6 changes: 3 additions & 3 deletions packages/vue-compat/src/runtime.ts
@@ -1,5 +1,5 @@
// This entry exports the runtime only, and is built as
// `dist/vue.esm-bundler.js` which is used by default for bundlers.
// `dist/vue.esm-bundler.mjs` which is used by default for bundlers.
import { createCompatVue } from './createCompatVue'
import { warn } from '@vue/runtime-core'

Expand All @@ -10,9 +10,9 @@ Vue.compile = (() => {
warn(
`Runtime compilation is not supported in this build of Vue.` +
(__ESM_BUNDLER__
? ` Configure your bundler to alias "vue" to "@vue/compat/dist/vue.esm-bundler.js".`
? ` Configure your bundler to alias "vue" to "@vue/compat/dist/vue.esm-bundler.mjs".`
: __ESM_BROWSER__
? ` Use "vue.esm-browser.js" instead.`
? ` Use "vue.esm-browser.mjs" instead.`
: __GLOBAL__
? ` Use "vue.global.js" instead.`
: ``) /* should not happen */
Expand Down