Skip to content

Commit f7bdfb4

Browse files
committed
Switch to .mjs for ESM dev build
1 parent 906c393 commit f7bdfb4

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/create-vue-lib/src/template/base/config/packages/@projectName@/vite.config.mts.ejs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,26 @@ export default defineConfig(({ mode }): UserConfig => {
6969
}
7070
else if (format === 'es') {
7171
name += '.esm'
72+
extension = 'mjs'
7273
7374
if (mode === 'neutral') {
7475
name += '-bundler.prod'
7576
}
7677
else if (mode === 'production') {
7778
name += '-browser'
79+
extension = 'js'
7880
}
7981
}
82+
else {
83+
extension = 'cjs'
84+
}
8085
8186
if (mode === 'production') {
8287
name += '.prod'
8388
}
8489
else if (mode === 'development') {
8590
name += '.dev'
8691
}
87-
else if (mode === 'neutral') {
88-
extension = format === 'cjs' ? 'cjs' : 'mjs'
89-
}
9092
9193
return `${name}.${extension}`
9294
}

packages/docs/src/dist-files.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Inside `dist` you should see files like these:
2222
📄 my-lib.cjs
2323
📄 my-lib.css
2424
📄 my-lib.d.ts
25-
📄 my-lib.esm.dev.js
25+
📄 my-lib.esm.dev.mjs
2626
📄 my-lib.esm-browser.prod.js
2727
📄 my-lib.esm-bundler.prod.mjs
2828
📄 my-lib.global.dev.js
@@ -101,7 +101,7 @@ This file contains the TypeScript types. This should include type information fo
101101

102102
Tooling in the consuming application should pick this up automatically, as it's referenced from `package.json`.
103103

104-
### `<name>.esm.dev.js`
104+
### `<name>.esm.dev.mjs`
105105

106106
This file exposes the library as an ES module. It is intended to be used during development, either with a bundler or directly in the browser via `<script type="module">` and import maps.
107107

@@ -140,7 +140,7 @@ Some features of this build:
140140
- The global `__DEV__` flag will be set to `false` and dead code removed. This is only relevant if you're using it in your code.
141141
- SFCs will be compiled in production mode.
142142

143-
During development, you'd normally use `<name>.esm.dev.js` instead.
143+
During development, you'd normally use `<name>.esm.dev.mjs` instead.
144144

145145
### `<name>.esm-bundler.prod.mjs`
146146

@@ -151,7 +151,7 @@ Some features of this build:
151151
- The global `__DEV__` variable will depend on the bundler's value for `process.env.NODE_ENV`.
152152
- SFCs will be compiled in production mode.
153153

154-
From a bundler's perspective, the only significant difference between this build and the `<name>.esm.dev.js` build is that `.vue` files are built in production mode. If you aren't using `.vue` files in your library code then this file can be used in both development and production. That would be similar to libraries like Vue core, Vue Router and Pinia, which just have an `esm-bundler` build, with no distinction between `dev` and `prod`. In that scenario, `<name>.esm.dev.js` is only used in the browser, so it could be renamed to something like `<name>.esm-browser.dev.js`.
154+
From a bundler's perspective, the only significant difference between this build and the `<name>.esm.dev.mjs` build is that `.vue` files are built in production mode. If you aren't using `.vue` files in your library code then this file can be used in both development and production. That would be similar to libraries like Vue core, Vue Router and Pinia, which just have an `esm-bundler` build, with no distinction between `dev` and `prod`. In that scenario, `<name>.esm.dev.mjs` is only used in the browser, so it could be renamed to something like `<name>.esm-browser.dev.js`.
155155

156156
### `<name>.global.dev.js` and `<name>.global.prod.js`
157157

@@ -194,7 +194,7 @@ A single Vite build can produce multiple files, but those files must share most
194194
There's nothing special about having 3 builds, that's just how many we need to create the combinations we need. We generate 3 `esm` files in `dist`, so we need at least 3 builds to achieve that.
195195

196196
Roughly speaking:
197-
- `build:dev` - unminified development builds that can be served to the browser without further build tools: `<name>.esm.dev.js` and `<name>.global.dev.js`.
197+
- `build:dev` - unminified development builds that can be served to the browser without further build tools: `<name>.esm.dev.mjs` and `<name>.global.dev.js`.
198198
- `build:neutral` - unminified builds that won't go directly to the browser: `<name>.cjs` and `<name>.esm-bundler.prod.js`.
199199
- `build:prod` - minified production builds to be served directly to the browser: `<name>.esm.prod.js` and `<name>.global.prod.js`
200200

0 commit comments

Comments
 (0)