Support Webpack Resolver Plugins in Loader #658
Labels
bundler: webpack 📦
Issue is related to webpack bundler
cat: modules aliasing 🔗
Issue related to modules aliasing
cat: monorepo 🔱
Issues related to usage of linaria in monorepo
feature: proposal 💬
New feature proposal that needs to be discussed
Describe the feature
Currently the
linaria/loader
usesenhanced-resolve
for file resolution. It currently takes the webpackResolve.options.alias
andResolve.options.module
from thewebpack.config
however it doesn't take theResolve.options.plugins
. It would be great to support plugins here as well. I'd be interested to hear if leaving this out was intentional due to resolution issues, or just not yet required.Motivation
A project I am attempting to adopt
linaria
in has a custom resolver plugin for imports of the style:project
. For example,:themes/styles/utils/getSize
will resolve tosrc/themes/styles/utils/getSize
. The ":
" is shorthand for the/src/
folder. This monorepo is quite large, so adopting a new import pattern would be a large change.Possible implementations
The existing
enhanced-resolve
creation could also pass along plugins:linaria/src/loader.ts
Lines 66 to 79 in 47c8157
const resolveSync = enhancedResolve.create.sync( // this._compilation is a deprecated API // However there seems to be no other way to access webpack's resolver // There is this.resolve, but it's asynchronous // Another option is to read the webpack.config.js, but it won't work for programmatic usage // This API is used by many loaders/plugins, so hope we're safe for a while this._compilation?.options.resolve ? { ...resolveOptions, alias: this._compilation.options.resolve.alias, modules: this._compilation.options.resolve.modules, + plugins: this._compilation.options.resolve.plugins, } : resolveOptions );
Or it could be specified through
linaria/loader
options, though this would deviate from the existing pattern foralias
/modules
.I am happy to help with this change if it's a good first issue.
Related Issues
#630
The text was updated successfully, but these errors were encountered: