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

Bug/scss import 2 #45

Merged
merged 3 commits into from
May 28, 2019
Merged

Bug/scss import 2 #45

merged 3 commits into from
May 28, 2019

Conversation

charliegdev
Copy link
Owner

@charliegdev charliegdev commented May 28, 2019

Summary

This PR solves this issue about SCSS import. Resolves #38.

I was partly right: TypeScript can't find a definition file, which is why it complained. However, I was wrong to assume that I could solve it using one single global definition hack, like this:

declare module "*.scss" {
  const content: { [className: string]: string };
  export = content;
}

The hack was a bad idea anyway; I couldn't leverage TypeScript's type checking if I do that.

With some researching, I found out this article on Medium:

How to use CSS Modules with TypeScript and webpack

It contains instructions on how to generate .scss.d.ts files from .scss. With the definition files in place, the SCSS import issue is finally solved.

Tech Details

The article was written on May 11, 2017, so it was over 2 years old. Things have changed, and here is the gist:

Install typings-for-css-modules-loader

yarn add --dev typings-for-css-modules-loader

Change Webpack Config

Change the config in config/webpack.config.js like this:

diff

Rerun

After the changes, run yarn start again, and see the typing files generated. For example, for Task.module.scss with this content:

.container {
  margin: 10px auto !important;
  width: 95%;
}

.title {
  color: #106ba3 !important;
  text-decoration: none;
}

.buttons {
  margin-top: 10px;
}

.deleteButton {
  margin-left: 10px;
}

The typing file generated, Task.module.scss.d.ts, contains content like this:

export const container: string;
export const title: string;
export const buttons: string;
export const deleteButton: string;

There you go! All the errors are gone, and I can get Intellisense now:

scss-auto

@charliegdev charliegdev added the bug Something isn't working label May 28, 2019
@charliegdev charliegdev added this to the MVP milestone May 28, 2019
@charliegdev charliegdev self-assigned this May 28, 2019
@charliegdev charliegdev merged commit 3057431 into master May 28, 2019
@charliegdev charliegdev deleted the bug/scss-import-2 branch May 28, 2019 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Solve TypeScript typings path for SCSS imports
1 participant