-
Notifications
You must be signed in to change notification settings - Fork 31
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
[Feature]: Redirect in bundleless mode #140
Comments
Users may want to keep some import queries even after turning on redirect. I recommend that we can introduce a escape hatch to keep original and handle it more flexibly import fooUrl from './assets/foo.svg?url' // preserve this query
// result
import fooUrl from './assets/foo.mjs' // 😭 after introducing a escape hatch "!!" (or other flag to be discussed), so he can use below import fooUrl from '!!./assets/foo.svg?url' // keep original
// result
import fooUrl from './assets/foo.svg?url' // 😁 |
Your proposal is to keep only the query or not convert it at all? I see that your text says "keep some queries," but in the example, it ends up not converting anything at all through |
yeah, sorry about the confusing describtion, is to keep original |
What problem does this feature solve?
When
bundle: false
, aka bundleless mode, the import and export path should be redirected to ensure that it is linked to the correct output, e.g:import '. /index.less'
should be rewritten toimport '. /index.css'
import icon from '. /close.svg'
should be rewritten toimport icon from '... /asset/close.svg'
or toimport icon from '. /asset/close.svg'
import { a } from '@/alias'
should be rewritten toimport { a } from "./alias"
import * from './utils'
should be rewritten toimport * from './utils.mjs
orimport * from './utils.cjs
The redirect behaviour should take the
autoExtension
logic in Rslib as well as node/Typescript resolver logic into consider.In the existing code logic, we already do some redirect logic of
autoExtenson
by default when it is a relative pathrslib/packages/core/src/config.ts
Lines 488 to 513 in 4b5f674
And for same feature in Modern.js Module, the implement is based on AST, see https://github.com/web-infra-dev/modern.js/blob/main/packages/solutions/module-tools/src/builder/feature/redirect.ts and https://github.com/web-infra-dev/modern.js/blob/95090d23cc4109e46ad45d8cd613f0eed6204547/packages/solutions/module-tools/src/utils/dts.ts#L140-L223
What does the proposed API look like?
To implement this feature, we should both support js and DTS output:
This feature should be opt-in:
The text was updated successfully, but these errors were encountered: