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

Can this be a TypeScript plugin? #29

Open
mohsen1 opened this issue Apr 18, 2017 · 9 comments
Open

Can this be a TypeScript plugin? #29

mohsen1 opened this issue Apr 18, 2017 · 9 comments

Comments

@mohsen1
Copy link

mohsen1 commented Apr 18, 2017

I'm not familiar with TypeScript plugins as much as you are. You wrote one but I was wondering if this can become a TypeScript plugin that extends module resolution to CSS files?

@Quramy
Copy link
Owner

Quramy commented Apr 18, 2017

It's interesting 😄

For example, vue-ts-plugin allows to treat .vue files as TypeScript sources. Using the same technique, this idea might be realised.

@Quramy
Copy link
Owner

Quramy commented Apr 20, 2017

@cameron-martin
Copy link

The docs for Language Service Plugins suggests that this wouldn't work

TypeScript Language Service Plugins ("plugins") are for changing the editing experience only. The core TypeScript language remains the same. Plugins can't add new language features such as new syntax or different typechecking behavior, and plugins aren't loaded during normal commandline typechecking or emitting.

So I have no idea how that vue one works. Will have a little dig around in the next few days and report my findings :)

@mohsen1
Copy link
Author

mohsen1 commented Aug 7, 2017

GraphQL Plugin is editing only as well.

Follow this issue: microsoft/TypeScript#16607

@mohsen1
Copy link
Author

mohsen1 commented Aug 7, 2017

Note that it's possible to have your own tsserver and tsc that does custom module resolution. By overloading resolveModuleNames it's possible to make compiler think a .css file resolve to an actual TypeScript file. This is what's happening here.

@avif
Copy link

avif commented Aug 25, 2017

I was looking for something similar and came across this:
https://www.npmjs.com/package/ts-css-modules

There's no git repository associated with this package and I couldn't get it to work but you could look at the package content after installing it and see the approach used seems very possible.

Also, the readme instructs to install vue-ts-plugin instead of ts-css-modules.

@cameron-martin
Copy link

cameron-martin commented Aug 25, 2017

That was me starting to mess around with Typescript language service plugins (with the aim to create one for CSS modules). I didn't get very far though :(

@fabb
Copy link

fabb commented Jan 3, 2019

Here‘s something similar as a PostCSS plugin: https://github.com/ezavile/postcss-typescript-css

@FDiskas
Copy link

FDiskas commented Oct 18, 2021

It actually already exists npm i D typescript-plugin-css-modules

    "plugins": [
      {
        "name": "typescript-plugin-css-modules",
        "options": {
          "classnameTransform": "camelCase",
          "customMatcher": "\\.module\\.scss$"
        }
      }
    ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants