TypeStrong / tsify

Browserify plugin for compiling TypeScript
344 stars 75 forks source link

importing css causes problems #259

Closed hiyelbaz closed 4 years ago

hiyelbaz commented 4 years ago

A ts file containing import "./styles.css" statement gets transpiled into require("./styles.css") when using tsc command. As far as I understand, tsify is trying to transpile css files into js statements and it breaks the browserify pipeline. How can I make css files get handled by other plugins?

cartant commented 4 years ago

tsify works by compiling the content of the files from disk and then feeding the complied code back to Browserify. That means there is no mechanism for manipulating content with other Browserify plugins or transforms before tsify.

This also means that if the source cannot be compiled using tsc - the command-line compiler - it cannot be complied with tsify either. And I doubt there is a mechanism to compile CSS imports with tsc.

I no longer use tsify, but IIRC, I used require calls to import Angular templates - in the early days, before Angular had a CLI - you should be able to do the same with your CSS. If you use require("./styles.css") in your source, it should compile fine and Browserify can then handle doing whatever it is you want to do with the CSS.

hiyelbaz commented 4 years ago

I tried required and worked well. Thank you for quick response.