Closed hbj closed 3 years ago
This will be fixed in the next Nx release (12.6).
@jaysoo this has been only partially fixed. Here are the outstanding issues:
~
at the start and the other not). I have to add "includePaths": ["node_modules"]
to stylePreprocessorOptions
to make both work without the ~
.javascriptEnabled
set to true
while it's not set for the module configuration.It would really make sense to make both use the exact same options because it happens often that we import non-module files from module files, so they must work the same way otherwise importing would be impossible.
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Description
When working with React, module-based (e.g.
.module.less
) and non-module based (e.g..less
) CSS preprocessors use different options. If I take the example of LESS, we have the following differences:stylePreprocessorOptions
only works with.less
filesnode_modules
we have to use the~package/path/to/file
format in.module.less
andpackage/path/to/file
(without~
) in.less
files.less
files are configured with support for JS (optionjavascriptEnabled: true
) while.module.less
aren'tThe objective is to have both configurations use the same preprocessor options.
Motivation
This change would solve the following issues (non exhaustive list, these are things I faced):
stylePreprocessorOptions.includePaths
node_modules
Concrete example
I use ant design in my React project and I want to be able to adapt its theme and use its LESS variables in my code, so I have the following setup (all files are under
apps/my-app/src
):variables.less
styles.less
app/app.module.less
This setup doesn't work for different reasons:
app/app.module.less
importsvariables.less
which imports ant design files fromnode_modules
but uses the non-tilde format, so it will fail (if I add the tilde then thestyles.less
file will fail to compile because it needs the non-tilde format) => sovariables.less
can't be imported by both types of filesantd/lib/style/themes/default.less
imported byvariables.less
uses JS so it will fail to compile if we make the import inapp/app.module.less
work as module files don't support JSI'm currently working around the issues with a custom webpack file:
But it would be very helpful if we could just configure the preprocessors through
stylePreprocessorOptions
and have both module and non-module preprocessors behave the same.Suggested Implementation
One possible implementation would be to have the web plugin (which is the base of the react plugin) use the
stylePreprocessorOptions
configuration option and prepare all preprocessor configurations accordingly, then the react plugin could get these configs and use them directly without modification.Alternate Implementations
Another option would be to centralise all preprocessors configuration (module and non-module) in the web plugin and make them use the same options.