esbuild-css-modules-plugin
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -49,2 +49,3 @@ import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild'; | ||
cssModulesOption?: CssModulesOptions; | ||
filter?: RegExp; | ||
v2?: boolean; | ||
@@ -51,0 +52,0 @@ v2CssModulesOption?: { |
@@ -12,4 +12,4 @@ const path = require('path'); | ||
builtCssSuffix, | ||
modulesCssRegExp, | ||
builtModulesCssRegExp, | ||
getModulesCssRegExp, | ||
getBuiltModulesCssRegExp, | ||
getRelativePath, | ||
@@ -425,2 +425,4 @@ getBuildId | ||
await prepareBuild(build, options); | ||
const modulesCssRegExp = getModulesCssRegExp(options); | ||
const builtModulesCssRegExp = getBuiltModulesCssRegExp(options); | ||
@@ -427,0 +429,0 @@ // resolve xxx.module.css to xxx.module.css?esbuild-css-modules-plugin-building |
@@ -9,6 +9,24 @@ const path = require('path'); | ||
const builtCssSuffixRegExp = builtCssSuffix.replace('?', '\\?').replace(/\-/g, '\\-'); | ||
const modulesCssRegExp = /\.modules?\.css$/i; | ||
const builtModulesCssRegExp = new RegExp(`\\.modules?\\.css${builtCssSuffixRegExp}$`, 'i'); | ||
/** | ||
* getModulesCssRegExp | ||
* @param {import('..').Options} options | ||
* @returns {RegExp} | ||
*/ | ||
const getModulesCssRegExp = (options) => { | ||
return options.filter ?? /\.modules?\.css$/i | ||
} | ||
/** | ||
* getBuiltModulesCssRegExp | ||
* @param {import('..').Options} options | ||
* @returns {RegExp} | ||
*/ | ||
const getBuiltModulesCssRegExp = (options) => { | ||
const baseRegExp = getModulesCssRegExp(options); | ||
const baseRegExpSource = baseRegExp.source.endsWith('$') ? baseRegExp.source.slice(0, -1) : baseRegExp.source; | ||
return new RegExp(`${baseRegExpSource}${builtCssSuffixRegExp}$`, 'i'); | ||
} | ||
/** | ||
* getLogger | ||
@@ -45,3 +63,3 @@ * @param {import('..').Build} build | ||
window.__inject_${digest}__ = doInject; | ||
})(); | ||
})(); | ||
`; | ||
@@ -74,3 +92,3 @@ } | ||
window.__inject_${digest}__ = doInject; | ||
})(); | ||
})(); | ||
`; | ||
@@ -143,4 +161,4 @@ }; | ||
builtCssSuffix, | ||
modulesCssRegExp, | ||
builtModulesCssRegExp, | ||
getModulesCssRegExp, | ||
getBuiltModulesCssRegExp, | ||
buildingCssSuffix, | ||
@@ -147,0 +165,0 @@ getRelativePath, |
@@ -161,4 +161,8 @@ const path = require('path'); | ||
const setup = async (build, options) => { | ||
const filter = options.filter ?? /\.modules?\.css$/; | ||
const filterBaseSource = filter.source.endsWith('$') ? filter.source.slice(0, -1) : filter.source; | ||
const filterCssJS = new RegExp(`${filterBaseSource}\\.js$`); | ||
build.onResolve( | ||
{ filter: /\.modules?\.css$/, namespace: 'file' }, | ||
{ filter, namespace: 'file' }, | ||
onResolveFactory(build, options) | ||
@@ -168,3 +172,3 @@ ); | ||
build.onLoad( | ||
{ filter: /\.modules?\.css\.js$/, namespace: pluginNamespace }, | ||
{ filter: filterCssJS, namespace: pluginNamespace }, | ||
onLoadFactory(build, options) | ||
@@ -171,0 +175,0 @@ ); |
{ | ||
"name": "esbuild-css-modules-plugin", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "A esbuild plugin to bundle css modules into js(x)/ts(x).", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -54,2 +54,4 @@ # esbuild-css-modules-plugin | ||
filter: /\.modules?\.css$/i // Optional. Regex to filter certain CSS files. | ||
cssModulesOption: { | ||
@@ -56,0 +58,0 @@ // optional, refer to: https://github.com/madyankin/postcss-modules/blob/d7cefc427c43bf35f7ebc55e7bda33b4689baf5a/index.d.ts#L27 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35295
901
76