JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q12148F
  • License MIT

SWC plugin for automatic style imports (Rust implementation)

Package Exports

  • swc-import-plugin
  • swc-import-plugin/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (swc-import-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

swc-import-plugin

A SWC plugin for automatically importing component styles. Compatible with rspack.

Installation

npm install swc-import-plugin --save-dev

Usage with rspack

In your rspack configuration:

const swcImportPlugin = require('swc-import-plugin');

module.exports = {
  module: {
    rules: [
      {
        test: /\.[jt]sx?$/,
        exclude: /(node_modules|bower_components)/,
        use: {
          loader: 'swc-loader',
          options: {
            jsc: {
              parser: {
                syntax: 'typescript',
                tsx: true,
              },
              transform: {},
            },
            plugin: (m) => {
              return swcImportPlugin(m, [{
                libraryName: '@/components',
                stylePath: './style',
                customName: (name) => `@/components/${name}`,
                ignoreStylePathNotFound: true
              }]);
            }
          }
        }
      }
    ]
  }
};

Configuration Options

  • libraryName: The name of the library to process imports from
  • stylePath: The path to look for style files (can be relative or absolute)
  • customName: (Optional) A function to customize the component path
  • ignoreStylePathNotFound: (Optional) Whether to ignore missing style files (defaults to true)

Development

This plugin is written in Rust and compiled to WebAssembly. To build from source:

  1. Install Rust and cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Build the plugin:
cargo build --release
  1. The WebAssembly output will be available in the target/wasm32-unknown-unknown/release directory.

License

MIT