Skip to content
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

Not work with less and webpack when I choose webpack resolvers in less-loader #77

Closed
dancon opened this issue Feb 26, 2020 · 9 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@dancon
Copy link
Contributor

dancon commented Feb 26, 2020

----------- Update 2020-03-16 -----------
I have fixed the issue by writing a less-plugin-aliases that work with typescript-plugin-css-modules customRenderer, you just modify the config as below:

"compilerOptions": {
    "plugins": [
      {
        "name": "typescript-plugin-css-modules",
        "options": {
          // ...
          "customRenderer": "node_modules/less-plugin-aliases/lib/customRender.js"
        }
      }
    ],
    // ....
   "paths": {
        // config the paths
   }
}

You can use the less-plugin-aliases now, it works well in my project.

The plugin will read the tsconfig.json default to get the compilerOptions to resolve the @import ~xx case, and I also commit a PR that inject the compilerOptions into customRenderer from ts plugin (I think this way is more elegant and power more to customRenderer ), after that the less plugin will not read tsconfig.json anymore.


Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

As less-loader says, I can choose webpack resovler by prepending my @import path with ~, then the plugin does not work as expected.

Describe the solution you'd like
A clear and concise description of what you want to happen.

In less file:

@import '~styles/variables.less';

// some code

In tsconfig.json

{
    "compilerOptions": {
         ...
         "paths":  {
              "styles/*": [path to styles folder]
         }
         ...
   }
}

In webpack.config file I also defined resolver.alias

"styles": path to styles folder

Maybe when the plugin detect a @import path start begin ~, deal it with paths defined in tsconfig.json

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Now, I just use relative path to make it work, but it's ugly and nonportable.

Additional context
Add any other context or screenshots about the feature request here.

@mrmckeb mrmckeb self-assigned this Feb 27, 2020
@mrmckeb
Copy link
Owner

mrmckeb commented Feb 27, 2020

Hi @dancon, thanks for reporting this.

Can you please provide a small reproduction? I will then take a look and try to resolve this by the end of the weekend!

@mrmckeb mrmckeb added the bug Something isn't working label Feb 27, 2020
@mfpopa
Copy link

mfpopa commented Mar 4, 2020

EDIT: I moved this to #78 as it might be a different issue.

PS. thanks @mrmckeb for creating and maintaining this. It is a much better solution than the plugins/loaders/solutions that create .d.ts files next to each CSS/SCSS file.

@dancon
Copy link
Contributor Author

dancon commented Mar 5, 2020

@mrmckeb I'm so sorry for replying late, here is the reproduction repo, thank you for your greate job !

@mrmckeb
Copy link
Owner

mrmckeb commented Mar 9, 2020

Thanks @mfpopa.

Hi @dancon, this is not supported by Less natively, it's a feature of the loader. So the only way to make this work is to manually normalise the path based on the TS paths or something similar.

Would you like to try implementing that? If not, I can try over the weekend.

@dancon
Copy link
Contributor Author

dancon commented Mar 10, 2020

@mrmckeb Yes, I know why it doesn't work, and I'd love to fix it, but maybe by this weekend.

@dancon
Copy link
Contributor Author

dancon commented Mar 15, 2020

@mrmckeb Hi, I'm trying to add the feature support by writing a less plugin, please note that ~

@kozlovvski
Copy link

+1, this feature would be also awesome in sass/scss. I use CRA with sass-loader and baseUrl: "src/" in tsconfig.json, so later I can import variables in any scss file like this:

@import "~styles/variables" // assuming, that there is a file "src/styles/_variables.scss"

By the way, thanks for this great package, it really makes me not pull out hairs from my head while working. It would be nice to see this kind of feature implemented in Typescript by default in the future.

@mrmckeb mrmckeb added enhancement New feature or request help wanted Extra attention is needed and removed bug Something isn't working labels Apr 27, 2020
@mrmckeb
Copy link
Owner

mrmckeb commented Apr 27, 2020

I'll release this today, thanks!

@mrmckeb mrmckeb removed the help wanted Extra attention is needed label Apr 27, 2020
@mrmckeb
Copy link
Owner

mrmckeb commented Apr 27, 2020

This has been released, sorry for the long delay.

Please see: https://github.com/mrmckeb/typescript-plugin-css-modules/releases/tag/v2.3.0

@mrmckeb mrmckeb closed this as completed Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants