ts-transform-css-modules

Extract CSS classnames in TS files

MIT 9 个版本
安装
npm install ts-transform-css-modules
yarn add ts-transform-css-modules
pnpm add ts-transform-css-modules
bun add ts-transform-css-modules
README

ts-transform-css-modules

Greenkeeper badge

npm version travis

Extract css class names from required css module files for TypeScript. This plugin is based on css-modules-require-hook and so constructor opts are from that repo.

This allows you to do this in TS files:

// Import works
import * as css from 'foo.css'
// require also works
const foo = require('foo.css')

console.log(css.foo)

Append this to before in your compilation step. See compile.ts for more info.

Right now named imports will not work due to TS mangling import name after compilation.

// Those are NOT working
import css from 'foo.css'
import { button, badge } from 'foo.css'

Options

See css-modules-require-hook for a list of options.

Custom Options

tsImportResolver (path: string): string: This callback function allows you to override import path in ImportDeclaration for every CSS file we encounter. This is useful when dealing with project that uses paths aliases in tsconfig. This might not be necessary once https://github.com/Microsoft/TypeScript/issues/28276 is resolved.

Caveats

  1. Source map support might not be entirely accurate
版本列表
0.3.3 2018-11-14
0.3.2 2018-11-08
0.3.1 2018-11-07
0.3.0 2018-10-22
0.2.2 2017-11-13
0.2.1 2017-09-14
0.2.0 2017-09-14
0.1.4 2017-08-19
0.1.3 2017-05-04