developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8k stars 361 forks source link

[Feature Request] versioning output filename #1008

Closed iShawnWang closed 1 year ago

iShawnWang commented 1 year ago

It there any option to archive versioning output filename

Example:

  1. "main": "./dist/foo-1.7.3.cjs"
  2. "main":"./dist/1.7.3/foo.cjs"
rschristian commented 1 year ago

Not really, no. What would the purpose of this be?

iShawnWang commented 1 year ago

Maintenance an internal SDK for company with samantic version and changelog, it is a common demand to versioning the SDK file name, keep every version available, and publish to the OSS or CDN

iShawnWang commented 1 year ago

I am think about to implement like demo code here:

// package.json

{ 
    scripts: {
        build: 'node ./build.js'
    }
}
// build.js
import pkg from './package.json'

child_process.exec('npx microbundle -i src/index.ts --external none -f umd -o dist/xxx-${pkg.version}.js --sourcemap false --generateTypes false')
iShawnWang commented 1 year ago

I am think about to implement like demo code here:

// package.json

{ 
    scripts: {
        build: 'node ./build.js'
    }
}
// build.js
import pkg from './package.json'

child_process.exec('npx microbundle -i src/index.ts --external none -f umd -o dist/xxx-${pkg.version}.js --sourcemap false --generateTypes false')

Any better fantastic solution is welcome ~ Or may be we can looking forward to impl it by microbundle :D

rschristian commented 1 year ago

I don't think this really makes sense for Microbundle to implement.

CDNs already contain the package version; duplicating this information in the file name itself isn't really adding anything of value, as far as I can tell.

https://unpkg.com/preact@10.11.0/dist/preact.module.js?module

Vs

https://unpkg.com/preact@10.11.0/dist/11.10.0/preact.module.js?module

Additionally, what you suggest would require rewriting all fields in the packages.json for every single version published, which Microbundle definitely won't ever do itself.

-  "main": "./dist/1.7.3/index.cjs"
+  "main": "./dist/1.7.4/index.cjs"

I see a lot of additional complexity for no real gain. That is assuming you aren't forsaking the entire NPM/Node ecosystem, in which case none of these conventions or practices would apply I suppose, though that would be such a niche use case that I don't think it makes sense to support.

If you need to do this though a separate build script (as you've done) is exactly what I'd recommend. I think that would be your best bet.

iShawnWang commented 1 year ago

Agree !

In my case, the internal CDN is really simple and do not support package versioning, i will using build script for now. thanks for your really clear advice ~