Skip to content

Commit

Permalink
feat(css): remove support for @rspack/postcss-loader (#3873)
Browse files Browse the repository at this point in the history
feat(css):remove support for `@rspack/postcss-loader`
  • Loading branch information
hyf0 authored and hardfist committed Aug 15, 2023
1 parent 38605cd commit 7cf0c2c
Show file tree
Hide file tree
Showing 27 changed files with 3 additions and 378 deletions.
32 changes: 3 additions & 29 deletions crates/rspack_plugin_css/src/parser_and_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ use rspack_core::{
ParserAndGenerator, SourceType, TemplateContext,
};
use rspack_core::{ModuleDependency, RuntimeGlobals};
use rspack_error::{
internal_error, Diagnostic, IntoTWithDiagnosticArray, Result, TWithDiagnosticArray,
};
use rspack_error::{internal_error, IntoTWithDiagnosticArray, Result, TWithDiagnosticArray};
use rustc_hash::FxHashSet;
use sugar_path::SugarPath;
use swc_core::{
Expand Down Expand Up @@ -43,16 +41,9 @@ pub(crate) static CSS_MODULE_SOURCE_TYPE_LIST: &[SourceType; 2] =
pub(crate) static CSS_MODULE_EXPORTS_ONLY_SOURCE_TYPE_LIST: &[SourceType; 1] =
&[SourceType::JavaScript];

/// Compat for @rspack/postcss-loader css modules
#[derive(serde::Deserialize)]
struct RspackPostcssModules {
rspack_postcss_modules: String,
}

#[derive(Debug)]
pub struct CssParserAndGenerator {
pub config: CssConfig,
pub meta: Option<String>,
pub exports: Option<IndexMap<JsWord, Vec<CssClassName>>>,
}

Expand Down Expand Up @@ -80,14 +71,7 @@ impl ParserAndGenerator for CssParserAndGenerator {

fn size(&self, module: &dyn Module, source_type: &SourceType) -> f64 {
match source_type {
SourceType::JavaScript => {
// meta + `module.exports = ...`
self
.meta
.as_ref()
.map(|item| item.len() as f64 + 17.0)
.unwrap_or(0.0)
}
SourceType::JavaScript => 42.0,
SourceType::Css => module.original_source().map_or(0, |source| source.size()) as f64,
_ => unreachable!(),
}
Expand All @@ -96,7 +80,6 @@ impl ParserAndGenerator for CssParserAndGenerator {
fn parse(&mut self, parse_context: ParseContext) -> Result<TWithDiagnosticArray<ParseResult>> {
let ParseContext {
source,
additional_data,
module_type,
module_user_request,
resource_data,
Expand Down Expand Up @@ -206,13 +189,8 @@ impl ParserAndGenerator for CssParserAndGenerator {
dependencies
};

self.meta = additional_data.and_then(|data| if data.is_empty() { None } else { Some(data) });
self.exports = locals;

if self.exports.is_some() && let Some(meta) = &self.meta && serde_json::from_str::<RspackPostcssModules>(meta).is_ok() {
diagnostic.push(Diagnostic::warn("CSS Modules".to_string(), format!("file: {} is using `postcss.modules` and `builtins.css.modules` to process css modules at the same time, rspack will use `builtins.css.modules`'s result.", resource_data.resource_path.display()), 0, 0));
}

let new_source = if let Some(source_map) = source_map {
SourceMapSource::new(SourceMapSourceOptions {
value: code,
Expand Down Expand Up @@ -291,11 +269,7 @@ impl ParserAndGenerator for CssParserAndGenerator {
generate_context.compilation,
&self.config.modules.locals_convention,
)?
} else if let Some(meta) = &self.meta
&& let Ok(meta) = serde_json::from_str::<RspackPostcssModules>(meta)
{
format!("module.exports = {};\n", meta.rspack_postcss_modules)
} else if generate_context.compilation.options.dev_server.hot {
} else if generate_context.compilation.options.dev_server.hot {
"module.hot.accept();".to_string()
} else {
"".to_string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ impl Plugin for CssPlugin {
let builder = move || {
Box::new(CssParserAndGenerator {
config: config.clone(),
meta: None,
exports: None,
}) as Box<dyn ParserAndGenerator>
};
Expand Down
3 changes: 0 additions & 3 deletions packages/rspack/tests/configCases/postcss/basic/index.css

This file was deleted.

8 changes: 0 additions & 8 deletions packages/rspack/tests/configCases/postcss/basic/index.js

This file was deleted.

This file was deleted.

28 changes: 0 additions & 28 deletions packages/rspack/tests/configCases/postcss/basic/webpack.config.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

45 changes: 0 additions & 45 deletions packages/rspack/tests/configCases/postcss/modules-config/index.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7cf0c2c

Please # to comment.