-
Notifications
You must be signed in to change notification settings - Fork 30
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]: Design of JavaScript Redirect #548
Comments
To be determined:
|
|
|
We can read |
Are these two options you provided? |
This is a complete process. We only need to compose |
type Externals =
| {
strategy: 'prefer-tsconfig' | 'prefer-externals';
}
| boolean;
export type Redirect = {
style?: boolean;
externals?: Externals;
}; The default strategy is 'prefer-tsconfig'. |
LGTM. Maintain scalability while being compatible with previous configurations. |
The implementation has been updated to: export type JsRedirect = {
/**
* Whether to automatically redirect the import paths of JavaScript output files,
* compilerOptions.paths in tsconfig.json will be applied by default.
* @defaultValue `true`
*/
path?: boolean;
/**
* Whether to automatically add the file extension based on the JavaScript output files.
* @defaultValue `true`
*/
extension?: boolean;
};
export type Redirect = {
/** Controls the redirect of the import paths of JavaScript output files. */
js?: JsRedirect;
style?: boolean;
}; |
What problem does this feature solve?
Background: The relationship of alias/externals in bundle and bundleless mode
resolve.alias
output.external
to rewrite the external path,redirect
is also implemented viaexternal
functionality.Currently supported features in bundle and bundleless mode:
Modern.js Module related implementation
autoExtension: true
: controls output file extensionsredirect.alias
: controls whether to rewrite alias pathredirect.autoExtension
: rewrite import extension in output code, it will force add the extension as well (useautoExtension
as default value)Proposal of Rslib
The main principle to is to align the concept and configuration of
alias
in bundle mode andexternals
in bundleless mode to reduce the cognitive cost of usersredirect.externalsStrategy
'prefer-tsconfig' | 'prefer-externals'
'prefer-tsconfig'
Just like
resolve.externalsStrategy
in bundle mode, for bundleless mode, Rslib will automatically loadtsconfig.compilerOptions.paths
as alias and apply. While in bundleless mode, all path rewrite is performed viaexternals
.'prefer-tsconfig'
and'prefer-externals'
perform the same asresolve.externalsStrategy
about the strategy.redirect.relativeImportExtensions
boolean
true
Rename
redirect.autoExtension
in Modern.js Module (aligned with typescript),relativeImportExtensions
changes the extension in the output code which pointing to other output files that will be determined byautoExtension
.main files
Since only CommonJS only support the main files (https://nodejs.org/api/modules.html#all-together). By default:
index.mjs
(if exists).index.cjs
(if exists).For CommonJS output, do not patch the main file path, leave the path as it is. (I'm not quite sure, maybe we could add the main files directly 🤔)Examples overview
ESM output
import foo from './foo'
->import foo from './foo.mjs'
import foo from './foo.ts'
->import foo from './foo.mjs'
import foo from './foo.js'
->import foo from './foo.mjs'
import foo from './utils'
->import foo from './utils/index.mjs'
import foo from './utils/index'
->import foo from './utils/index.mjs'
CommonJS output
import foo from './foo'
->import foo from './foo.js'
import foo from './foo.ts'
->import foo from './foo.js'
import foo from './foo.js'
->import foo from './foo.js'
import foo from './utils'
->import foo from './utils'
import foo from './utils/index'
->import foo from './utils/index.js'
Compares with Modern.js Module
redirect.alias
redirect.externalsStrategy = false
as an alternative.redirect.autoExtension
redirect.rewriteRelativeImportExtensions
redirect.externalsStrategy
What does the proposed API look like?
/
The text was updated successfully, but these errors were encountered: