heiseshandian / dynamic-alias-resolve-plugin Goto Github PK
View Code? Open in Web Editor NEWdynamic alias, enhanced-resolve plugin
dynamic alias, enhanced-resolve plugin
The test pattern used across my webpack config is /\.(js|mjs|jsx|ts|tsx)$/
This leads to the dynamic
function never being called.
Using a slight tweak to the example /\.ts$/
also leads to dynamic
function never being called.
The repo is full of .ts, .tsx, and .js files.
/.*/
is the only way I've found so far to get the function passed to dynamic
getting called.
Tested via a build script with
new DynamicAliasResolvePlugin({
alias: "lib",
dynamic: (request, alias) => {
throw new Error()
},
pattern: /.*/,
// pattern: /\.(js|mjs|jsx|ts|tsx)$/,
})
Using this setup and it does return absolute paths as desired, however the webpack build fails.
new DynamicAliasResolvePlugin({
alias: ["lib", "components"],
dynamic: (request, alias) => {
console.log({ request })
let resolvedPath
if (request.descriptionFileData.name === 'shared') {
resolvedPath = path.resolve(paths.shared, request.request)
} else {
resolvedPath = path.resolve(paths.appSrc, request.request)
}
console.log({ resolvedPath })
return resolvedPath
},
pattern: /.*/,
}),
console.log
output confirms paths:
{
request: {
context: {
issuer: '/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/utils/cookie/cookieUtils.ts',
compiler: undefined
},
path: '/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/utils/cookie',
request: 'lib/constants/cookieConstants',
query: '',
module: true,
directory: false,
file: false,
descriptionFilePath: '/Users/me/Documents/co/repos/client/workspaces/shared/package.json',
descriptionFileData: {
name: 'shared',
version: '0.1.0',
private: true,
type: 'module',
scripts: [Object],
browserslist: [Object],
eslintConfig: [Object],
jest: [Object]
},
descriptionFileRoot: '/Users/me/Documents/co/repos/client/workspaces/shared',
relativePath: './src/lib/utils/cookie'
}
}
{
resolvedPath: '/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/constants/cookieConstants'
}
Yet getting this error:
Failed to compile.
/Users/me/Documents/co/repos/client/workspaces/shared/src/lib/utils/cookie/cookieUtils.ts
Cannot find module: 'lib/constants/cookieConstants'. Make sure this package is installed.
Please provide examples is this isn't the correct way to use this plugin.
If someone write import A from @/A
, it can be import @/A.ts
or @/A/index.ts
. Your plugin cannot handle @/A/index.ts
case.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.