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

feat(dev): add sourcemapBaseUrl for plugin-legacy #19281

Open
wants to merge 3 commits 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/plugin-legacy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ npm add -D terser

Set to `false` to only output the legacy bundles that support all target browsers.

### `sourcemapBaseUrl`

- **Type:** `string`
- **Default:** `undefined`

Set custom base url for sourcemaps. Inherited from from `build.rollupOptions.output.sourcemapBaseUrl` option in `vite.config.js`.

## Browsers that supports ESM but does not support widely-available features

The legacy plugin offers a way to use widely-available features natively in the modern build, while falling back to the legacy build in browsers with native ESM but without those features supported (e.g. Legacy Edge). This feature works by injecting a runtime check and loading the legacy bundle with SystemJs runtime if needed. There are the following drawbacks:
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-legacy/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
apply: 'build',

async generateBundle(opts, bundle) {
const sourcemapBaseUrl = options.sourcemapBaseUrl || opts.sourcemapBaseUrl
if (config.build.ssr) {
return
}
Expand Down Expand Up @@ -309,6 +310,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
config.build,
'es',
opts,
sourcemapBaseUrl,
true,
genLegacy,
)
Expand Down Expand Up @@ -353,6 +355,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
config.build,
'iife',
opts,
sourcemapBaseUrl,
options.externalSystemJS,
)
}
Expand Down Expand Up @@ -785,6 +788,7 @@ async function buildPolyfillChunk(
buildOptions: BuildOptions,
format: 'iife' | 'es',
rollupOutputOptions: NormalizedOutputOptions,
sourcemapBaseUrl?: string,
excludeSystemJS?: boolean,
prependModenChunkLegacyGuard?: boolean,
) {
Expand Down Expand Up @@ -812,6 +816,7 @@ async function buildPolyfillChunk(
output: {
format,
hashCharacters: rollupOutputOptions.hashCharacters,
sourcemapBaseUrl,
entryFileNames: rollupOutputOptions.entryFileNames,
},
},
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-legacy/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export interface Options {
* default: true
*/
renderModernChunks?: boolean
sourcemapBaseUrl?: string
}
Loading