All Projects β†’ Megaputer β†’ dts-css-modules-loader

Megaputer / dts-css-modules-loader

Licence: other
A small Webpack loader to generate typings for your CSS-Modules

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to dts-css-modules-loader

typed-css-modules-loader
πŸ’  Webpack loader for typed-css-modules auto-creation
Stars: ✭ 62 (+40.91%)
Mutual labels:  loader, css-modules
rollup-loader
Rollup does what it can do, and let Webpack finish the job.
Stars: ✭ 86 (+95.45%)
Mutual labels:  loader
moonlight-admin
Easy to use admin panel, designed for cheat loaders.
Stars: ✭ 29 (-34.09%)
Mutual labels:  loader
nunjucks-loader
Webpack loader for Nunjucks templates
Stars: ✭ 20 (-54.55%)
Mutual labels:  loader
typings-sanctuary
*UNMAINTAINED* type definitions (for TypeScript) for JavaScript library Sanctuary
Stars: ✭ 12 (-72.73%)
Mutual labels:  typings
faker
A kotlin extension to load images asynchronously on android
Stars: ✭ 58 (+31.82%)
Mutual labels:  loader
Prevailer-orientation-support-library-for-Android
Prevailer is a simple android library that helps in preserving object instances across orientation change in android and is JAVA 8 and MVP ready.
Stars: ✭ 17 (-61.36%)
Mutual labels:  loader
vue-visual
Vue 2 image and video loader supporting lazy loading, background videos, fixed aspect ratios, low rez poster images, transitions, loaders, slotted content and more.
Stars: ✭ 56 (+27.27%)
Mutual labels:  loader
architectury-api
An intermediary api aimed at easing development of multiplatform mods.
Stars: ✭ 139 (+215.91%)
Mutual labels:  loader
memory-module-loader
An implementation of a Windows loader that can load dynamic-linked libraries (DLLs) directly from memory
Stars: ✭ 111 (+152.27%)
Mutual labels:  loader
rprogress
React ajax loader progress bar with clear API
Stars: ✭ 12 (-72.73%)
Mutual labels:  loader
react-intl-loader
Async react-intl locale data loader for webpack
Stars: ✭ 46 (+4.55%)
Mutual labels:  loader
LoadersPack-Android
Android LoadersPack - a replacement of default android material progressbar with different loaders
Stars: ✭ 119 (+170.45%)
Mutual labels:  loader
favicon-canvas-loader
Create and display a circular loading <canvas> animation as a webpage favicon.
Stars: ✭ 83 (+88.64%)
Mutual labels:  loader
CsharpVoxReader
A generic C# reader for MagicaVoxel's vox file format
Stars: ✭ 15 (-65.91%)
Mutual labels:  loader
webgpu-seed
πŸ”ΊπŸŒ± An example on how to render a hello triangle with WebGPU.
Stars: ✭ 178 (+304.55%)
Mutual labels:  typings
css-modules-angular2
Css modules working with Angular2
Stars: ✭ 22 (-50%)
Mutual labels:  css-modules
react-shop
Shop example for mobile web
Stars: ✭ 20 (-54.55%)
Mutual labels:  css-modules
phaser-webpack-loader
Asset loader for Phaser + Webpack.
Stars: ✭ 85 (+93.18%)
Mutual labels:  loader
webpack-typescript-react
Webpack 5 boilerplate with support of most common loaders and modules (see tags and description)
Stars: ✭ 185 (+320.45%)
Mutual labels:  css-modules

dts-css-modules-loader

A small Webpack loader to generate typings for your CSS-Modules. Created as a replacement for the frozend typings-for-css-modules-loader. This loader does not make any changes in content of styles, just creates *.d.ts file during the work. It is assumed that the content will be preprocessed first by css-loader.

Installation

npm i -D dts-css-modules-loader
# or
yarn add -D dts-css-modules-loader

Usage

{
  test: /\.scss$/,
  use: [
    {
      loader: 'style-loader',
      options: {
        esModule: false,
      },
    },
    {
      loader: 'dts-css-modules-loader',
      options: {
        namedExport: true
      }
    },
    {
      loader: 'css-loader',
      options: {
        // options for the v5 of css-loader
        modules: {
          exportLocalsConvention: 'camelCaseOnly',
          localIdentName: '[local]'
        }
      }
    },
    'sass-loader'
  ]
}

Options

namedExport

When the option is switched on classes exported as variables. Be sure you using camelCase option of css-loader to avoid invalid name of variables.

// This file is generated automatically.
export const button: string;
export const buttonActive: string;

When option is off:

// This file is generated automatically.
export interface I_buttonScss {
  'button': string
  'buttonActive': string
}
declare const styles: I_buttonScss;
export = styles;

banner

Adds a "banner" prefix to each generated file.

customTypings

A function that accepts classes (an array of string) and returns the content of declaration file:

customTypings: classes => {
  let content = '// This file is generated automatically\ndeclare const styles: {\n';
  for (const c of classes) {
    content += `  ${c}: string;\n`;
  }
  content += '};\nexport default styles;\n';
  return content;
}

namedExport and banner option will be ignored

dropEmptyFile

If there are no classes, the typings file will not be generated, and the existing will be deleted.

Usage in Typescript

import * as styles from './_button.scss';

To avoid errors about the absent module, you need to determine this:

/**
 * Trap for `*.scss.d.ts` files which are not generated yet.
 */
declare module '*.scss' {
  var classes: any;
  export = classes;
}

When you add new classname Typescript compiler may not find the generated variable so you need to compile twice your files.

License

Licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].