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 fromstylePath
: The path to look for style files (can be relative or absolute)customName
: (Optional) A function to customize the component pathignoreStylePathNotFound
: (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:
- Install Rust and cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Build the plugin:
cargo build --release
- The WebAssembly output will be available in the
target/wasm32-unknown-unknown/release
directory.
License
MIT