Open unilynx opened 3 years ago
Also wanna filter by importer, because I wanna figure out all the first required packages, I just do like bellow:
module.exports = {
name: 'onlyShallowDependencies',
setup(build) {
build.onResolve({ filter: /./ }, args => {
if (/node_modules/.test(args.importer)) {
return { path: args.path, external: true }
} else {
return undefined
}
})
},
}
Which will mark package's requirement as external!
Maybe like this: 🤪
module.exports = {
name: 'onlyShallowDependencies',
setup(build) {
build.onResolve({ filter: { filed: 'importer', regex: /node_modules/ } }, args => {
return { path: args.path, external: true }
})
},
}
A plugin's onResolve can filter by path and namespace, but it would be nice to add 'kind' to this too
My use case: I want to allow
to point to an external asset without further processing. onResolves receives this path as follows from the css loader:
But almost every path starts with '/', making the regex filter
/^\//
not that effective. Filtering on url-token would limit the amount of paths sent back to JavaScript for resolving.