Package Exports
- @asn.aeb/esbuild-css-modules-plugin
- @asn.aeb/esbuild-css-modules-plugin/lib/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 (@asn.aeb/esbuild-css-modules-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
esbuild CSS Modules Plugin
This plugin has been made because none of the actual css-modules plugins allow to work with Server-Side-Rendering and the ones that do, are outdated. In this initial iteration, it works in two ways:
- For use with
bundle: true: Bundles css class names into thejsbundles and output a single.cssfile containing all the css from*.module.css's with correct identifiers. Ideal for client side stuff where you want to bundle everything. - For use with
bundle: false: Creates*.module.jsfiles in place of*.module.cssand updatesimportorrequirestatements accordingly. Ideal for SSR where you want to output the html with the correct class names. The.cssbundle can still be emitted.
Usage
Use case 1 - Bundle js files and create a single bundle.css file as well.
esbuild.build({
entryPoints: ['src/index.tsx'],
// You should use this in place of `outfile`
outdir: 'static/js',
bundle: true
plugins: [cssModulesPlugin({
// Optional. Will not emit the bundle if omitted.
emitCssBundle: {
// Optional. Defaults to the value of `outdir`
path: 'static/css'
// Required. Will append `.css` at the end if missing
filename: 'bundle'
}
})]
})Use case 2 - Upload the files to the server for SSR, preserving the folder structure without bundling. This example uses glob for pattern matching.
esbuild.build({
// `.css` files must be included in entryPoints when `bundle: false`
entryPoints: await glob('src/**/*.{ts,tsx,css}'),
outdir: 'server/ssr',
bundle: false,
// emitCssBundle can be used as well if needed. It will produce the same result regardless of `bundle` setting
plugins: [cssModulesPlugin()]
})Coming
More features will be added in the next future.