Skip to content

umijs/swc-plugin-auto-css-modules

Repository files navigation

swc-plugin-auto-css-modules

Auto css modules plugin for swc.

Install

  pnpm i -D swc-plugin-auto-css-modules

You should install the following versions:

@swc/core version working version
latest > version >= 1.4.0 swc-plugin-auto-css-modules@1.6.0
1.3.108 > version >= 1.3.106 Not support
1.3.106 > version >= 1.3.63 swc-plugin-auto-css-modules@1.5.0
1.3.63 > version >= 1.3.41 swc-plugin-auto-css-modules@1.4.0
1.3.41 > version >= 1.3.24 swc-plugin-auto-css-modules@1.3.0

Usage

// swc config
{
  jsc: {
    experimental: {
      plugins: [
+       ['swc-plugin-auto-css-modules', {}]
      ],
    },
  }
}

Auto css modules

This plugin will auto add the ?modules suffix.

import styles from './index.less'
// to
import styles from './index.less?modules'

Lock core-js import

Lock core-js import by config lock_core_js_pkg_path.

plugins: [
  [
    'swc-plugin-auto-css-modules',
    { lock_core_js_pkg_path: dirname(require.resolve('core-js/package.json')) },
  ],
]
import 'core-js/es/modules'
// to
import '/node_modules/**/core-js/es/modules'

Config

See types file

import type { ISwcPluginAutoCssModulesConfig } from 'swc-plugin-auto-css-modules'

License

MIT