Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: builtin:lightningcss-loader shuold keep loader query #7363

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn get_builtin_loader(builtin: &str, options: Option<&str>) -> BoxLoader {
});
// TODO: builtin-loader supports function
return Arc::new(rspack_loader_lightningcss::LightningCssLoader::new(
None, config,
None, config, builtin,
));
}

Expand Down
8 changes: 6 additions & 2 deletions crates/rspack_loader_lightningcss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ pub struct LightningCssLoader {
}

impl LightningCssLoader {
pub fn new(visitors: Option<Vec<LightningcssLoaderVisitor>>, config: Config) -> Self {
pub fn new(
visitors: Option<Vec<LightningcssLoaderVisitor>>,
config: Config,
ident: &str,
) -> Self {
Self {
id: LIGHTNINGCSS_LOADER_IDENTIFIER.into(),
id: ident.into(),
visitors: visitors.map(|v| Mutex::new(v)),
config,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_loader_react_refresh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl ReactRefreshLoader {
/// Panics:
/// Panics if `identifier` passed in is not starting with `builtin:react-refresh-loader`.
pub fn with_identifier(mut self, identifier: Identifier) -> Self {
assert!(identifier.starts_with(REACT_REFRESH_LOADER_IDENTIFIER));
debug_assert!(identifier.starts_with(REACT_REFRESH_LOADER_IDENTIFIER));
self.identifier = identifier;
self
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
user-select: none;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import './index.css'

const fs = require("node:fs");
const path = require("node:path");

it("should transform CSS and add prefixes correctly", () => {
const css = fs.readFileSync(
path.resolve(__dirname, "./bundle0.css"),
"utf-8"
);

expect(css.includes('-ms-user-select: none;')).toBeTruthy();
expect(css.includes('user-select: none;')).toBeTruthy();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const rspack = require("@rspack/core");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
module: {
rules: [
{
test: /\.css$/,
use: [
rspack.CssExtractRspackPlugin.loader,
"css-loader",
{
loader: "builtin:lightningcss-loader",
/** @type {import("@rspack/core").LightningcssLoaderOptions} */
options: {
targets: [
'Edge >= 12'
]
}
}
],
type: "javascript/auto"
}
]
},
plugins: [
new rspack.CssExtractRspackPlugin({
filename: 'bundle0.css'
})
],
experiments: {
css: true
}
};
5 changes: 3 additions & 2 deletions packages/rspack/src/config/adapterRuleUse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ const getLightningcssLoaderOptions: GetLoaderOptions = (o, _) => {
o.targets = browserslistToTargets(browserslist(o.targets));
}

if (o.include) {
if (o.include && typeof o.include === "object") {
o.include = toFeatures(o.include as unknown as FeatureOptions);
}

if (o.exclude) {
if (o.exclude && typeof o.exclude === "object") {
o.exclude = toFeatures(o.exclude as unknown as FeatureOptions);
}
}

return o;
};

Expand Down
Loading