diff --git a/Cargo.lock b/Cargo.lock index cbe920881c2..3d7024d51db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4227,6 +4227,7 @@ dependencies = [ "rspack_core", "rspack_error", "rspack_hook", + "rspack_plugin_css", "rspack_plugin_javascript", "rspack_util", "rustc-hash 1.1.0", diff --git a/crates/rspack_plugin_css/src/lib.rs b/crates/rspack_plugin_css/src/lib.rs index ac0aeca41d2..ee7a8e29d5c 100644 --- a/crates/rspack_plugin_css/src/lib.rs +++ b/crates/rspack_plugin_css/src/lib.rs @@ -4,7 +4,7 @@ #![feature(option_get_or_insert_default)] pub mod dependency; -mod parser_and_generator; +pub mod parser_and_generator; pub mod plugin; pub mod runtime; mod utils; diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index ca484ccf152..925ed62044f 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -24,7 +24,7 @@ use rustc_hash::FxHashSet; use crate::{ dependency::CssSelfReferenceLocalIdentDependency, - utils::{css_modules_exports_to_string, escape_css, LocalIdentOptions}, + utils::{css_modules_exports_to_string, LocalIdentOptions}, }; use crate::{ dependency::CssSelfReferenceLocalIdentReplacement, @@ -47,7 +47,8 @@ static REGEX_IS_MODULES: LazyLock = static REGEX_IS_COMMENTS: LazyLock = LazyLock::new(|| Regex::new(r"/\*[\s\S]*?\*/").expect("Invalid regex")); -pub(crate) static CSS_MODULE_SOURCE_TYPE_LIST: &[SourceType; 1] = &[SourceType::Css]; +pub(crate) static CSS_MODULE_SOURCE_TYPE_LIST: &[SourceType; 2] = + &[SourceType::Css, SourceType::JavaScript]; pub(crate) static CSS_MODULE_EXPORTS_ONLY_SOURCE_TYPE_LIST: &[SourceType; 1] = &[SourceType::JavaScript]; @@ -79,6 +80,7 @@ pub struct CssParserAndGenerator { pub named_exports: bool, pub es_module: bool, pub exports: Option, + pub hot: bool, } impl ParserAndGenerator for CssParserAndGenerator { @@ -443,71 +445,6 @@ impl ParserAndGenerator for CssParserAndGenerator { data: generate_context.data, }; - let identifier = module.identifier(); - let module_id = compilation - .chunk_graph - .get_module_id(identifier) - .unwrap_or_default(); - - if let Some(exports) = &self.exports { - let mg = compilation.get_module_graph(); - let unused = get_unused_local_ident(exports, identifier, generate_context.runtime, &mg); - context.data.insert(unused); - - let used = get_used_exports(exports, identifier, generate_context.runtime, &mg); - - static RE: LazyLock = - LazyLock::new(|| Regex::new(r#"\\"#).expect("should compile")); - let module_id = RE.replace_all(module_id, "/"); - - let meta_data = used - .iter() - .map(|(n, v)| { - let escaped = escape_css(n, false); - v.iter() - .map(|v| { - let composed = &v.id; - - if let Some(composed) = composed { - let mg = compilation.get_module_graph(); - let module = mg - .get_module_by_dependency_id(composed) - .expect("should have from dependency"); - let module_id = compilation - .chunk_graph - .get_module_id(module.identifier()) - .expect("should have module id"); - - format!( - "{}:{}@{}/", - escaped, - escape_css(module_id, false), - escape_css(&v.ident, false) - ) - } else { - format!("{}:{}/", escaped, escape_css(&v.ident, false)) - } - }) - .collect::>() - .join("") - }) - .collect::>() - .join(""); - - context.data.insert(CssUsedExports(format!( - "{}{}{}", - meta_data, - if self.es_module { "&" } else { "" }, - escape_css(&module_id, false) - ))); - } else { - context.data.insert(CssUsedExports(format!( - "{}{}", - if self.es_module { "&" } else { "" }, - escape_css(module_id, false) - ))); - } - module.get_dependencies().iter().for_each(|id| { if let Some(dependency) = compilation .get_module_graph() @@ -530,11 +467,15 @@ impl ParserAndGenerator for CssParserAndGenerator { Ok(source.boxed()) } SourceType::JavaScript => { + let with_hmr = self.hot; let exports = if generate_context.concatenation_scope.is_some() { + // currently this is dead branch, as css module will never be concatenated expect exportsOnly let mut concate_source = ConcatSource::default(); if let Some(ref exports) = self.exports { let mg = generate_context.compilation.get_module_graph(); - + let unused_exports = + get_unused_local_ident(exports, module.identifier(), generate_context.runtime, &mg); + generate_context.data.insert(unused_exports); let exports = get_used_exports(exports, module.identifier(), generate_context.runtime, &mg); @@ -560,20 +501,47 @@ impl ParserAndGenerator for CssParserAndGenerator { ("", "", "") }; if let Some(exports) = &self.exports { + let unused_exports = + get_unused_local_ident(exports, module.identifier(), generate_context.runtime, &mg); + generate_context.data.insert(unused_exports); + let exports = get_used_exports(exports, module.identifier(), generate_context.runtime, &mg); - css_modules_exports_to_string( - exports, - module, - generate_context.compilation, - generate_context.runtime_requirements, + if with_hmr { + format!( + "{}\nmodule.hot.accept();\n", + css_modules_exports_to_string( + exports, + module, + generate_context.compilation, + generate_context.runtime_requirements, + ns_obj, + left, + right, + )? + ) + } else { + css_modules_exports_to_string( + exports, + module, + generate_context.compilation, + generate_context.runtime_requirements, + ns_obj, + left, + right, + )? + } + } else { + format!( + "{}{}module.exports = {{}}{};\n{}", ns_obj, left, right, - )? - } else { - format!("{}{}module.exports = {{}}{};\n", ns_obj, left, right) + with_hmr + .then_some("module.hot.accept();\n") + .unwrap_or_default() + ) } }; generate_context @@ -601,7 +569,13 @@ impl ParserAndGenerator for CssParserAndGenerator { _mg: &ModuleGraph, _cg: &ChunkGraph, ) -> Option> { - Some("Module Concatenation is not implemented for CssParserAndGenerator".into()) + if self.exports_only { + None + } else { + // CSS Module cannot be concatenated as it must appear in css chunk, if it's + // concatenated, it will be removed from module graph + Some("Module Concatenation is not implemented for CssParserAndGenerator".into()) + } } fn update_hash( @@ -628,7 +602,7 @@ fn get_used_exports<'a>( let export_info = mg.get_read_only_export_info(&identifier, name.as_str().into()); if let Some(export_info) = export_info { - !matches!(export_info.get_used(mg, runtime), UsageState::Unused) + export_info.get_used(mg, runtime) != UsageState::Unused } else { true } @@ -668,6 +642,3 @@ fn get_unused_local_ident( .collect(), } } - -#[derive(Debug, Clone)] -pub struct CssUsedExports(pub String); diff --git a/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs b/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs index a0520d6c9a6..010763480e3 100644 --- a/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs +++ b/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs @@ -24,11 +24,9 @@ use rspack_hook::plugin_hook; use rspack_plugin_runtime::is_enabled_for_chunk; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; -use crate::parser_and_generator::{ - CodeGenerationDataUnusedLocalIdent, CssParserAndGenerator, CssUsedExports, -}; +use crate::parser_and_generator::{CodeGenerationDataUnusedLocalIdent, CssParserAndGenerator}; use crate::runtime::CssLoadingRuntimeModule; -use crate::utils::{escape_css, AUTO_PUBLIC_PATH_PLACEHOLDER}; +use crate::utils::AUTO_PUBLIC_PATH_PLACEHOLDER; use crate::{plugin::CssPluginInner, CssPlugin}; struct CssModuleDebugInfo<'a> { @@ -62,8 +60,6 @@ impl CssPlugin { chunk: &Chunk, ordered_css_modules: &[&dyn Module], ) -> rspack_error::Result { - let mut meta_data = vec![]; - let with_compression = compilation.options.output.css_head_data_compression; let module_sources = ordered_css_modules .iter() .map(|module| { @@ -71,9 +67,6 @@ impl CssPlugin { let code_gen_result = compilation .code_generation_results .get(module_id, Some(chunk.runtime())); - if let Some(meta_data_str) = code_gen_result.data.get::() { - meta_data.push(meta_data_str.0.as_str()); - } Ok( code_gen_result @@ -83,7 +76,7 @@ impl CssPlugin { }) .collect::>>()?; - let mut source = module_sources + let source = module_sources .into_par_iter() // TODO(hyf0): I couldn't think of a situation where a module doesn't have `Source`. // Should we return a Error if there is a `None` in `module_sources`? @@ -105,23 +98,6 @@ impl CssPlugin { acc }); - let name_with_id = format!( - "{}-{}", - &compilation.options.output.unique_name, - chunk.id().unwrap_or_default() - ); - let meta_data_str = format!( - "head{{--webpack-{}:{};}}", - escape_css(&name_with_id, true), - if with_compression { - lzw_encode(&meta_data.join(",")) - } else { - meta_data.join(",") - } - ); - - source.add(RawSource::from(meta_data_str)); - Ok(source) } @@ -257,50 +233,6 @@ async fn content_hash( Ok(()) } -fn lzw_encode(input: &str) -> String { - if input.is_empty() { - return input.into(); - } - let mut map: HashMap = HashMap::default(); - let mut encoded = String::new(); - let mut phrase = input.chars().next().expect("should have value").to_string(); - let mut code = 256u16; - let max_code = 0xFFFF; - - for c in input.chars().skip(1) { - let next_phrase = format!("{}{}", phrase, c); - if map.contains_key(&next_phrase) { - phrase = next_phrase; - } else { - if phrase.len() > 1 { - encoded.push(*map.get(&phrase).expect("should convert to u32 correctly")); - } else { - encoded += &phrase; - } - if code <= max_code { - map.insert( - next_phrase, - std::char::from_u32(code as u32).expect("should convert to u32 correctly"), - ); - code += 1; - } - if code > max_code { - code = 256; - map.clear(); - } - phrase = c.to_string(); - } - } - - if phrase.len() > 1 { - encoded.push(*map.get(&phrase).expect("should have phrase")); - } else { - encoded += &phrase; - } - - encoded -} - #[plugin_hook(CompilationRenderManifest for CssPlugin)] async fn render_manifest( &self, @@ -453,6 +385,7 @@ impl Plugin for CssPlugin { exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), es_module: g.es_module.expect("should have es_module"), + hot: false, }) as Box }), ); @@ -479,6 +412,7 @@ impl Plugin for CssPlugin { exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), es_module: g.es_module.expect("should have es_module"), + hot: false, }) as Box }), ); @@ -505,6 +439,7 @@ impl Plugin for CssPlugin { exports_only: g.exports_only.expect("should have exports_only"), named_exports: p.named_exports.expect("should have named_exports"), es_module: g.es_module.expect("should have es_module"), + hot: false, }) as Box }), ); diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_with_hmr.js b/crates/rspack_plugin_css/src/runtime/css_loading_with_hmr.js index 7357207863a..66f55c742d1 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_with_hmr.js +++ b/crates/rspack_plugin_css/src/runtime/css_loading_with_hmr.js @@ -14,7 +14,7 @@ var applyHandler = function (options) { } while (newTags.length) { var info = newTags.pop(); - var chunkModuleIds = loadCssChunkData(__webpack_require__.m, info[1], info[0]); + var chunkModuleIds = loadCssChunkData(__webpack_require__.m, info[0]); chunkModuleIds.forEach(function(id) { moduleIds.push(id) }); diff --git a/crates/rspack_plugin_css/src/runtime/css_loading_with_loading.js b/crates/rspack_plugin_css/src/runtime/css_loading_with_loading.js index f0728aead5a..2d4a332c139 100644 --- a/crates/rspack_plugin_css/src/runtime/css_loading_with_loading.js +++ b/crates/rspack_plugin_css/src/runtime/css_loading_with_loading.js @@ -42,7 +42,7 @@ __webpack_require__.f.css = function (chunkId, promises, fetchPriority) { error.request = realSrc; installedChunkData[1](error); } else { - loadCssChunkData(__webpack_require__.m, link, chunkId); + loadCssChunkData(__webpack_require__.m, chunkId); installedChunkData[0](); } } diff --git a/crates/rspack_plugin_css/src/runtime/mod.rs b/crates/rspack_plugin_css/src/runtime/mod.rs index 523f9510b39..4b9d38a2dd2 100644 --- a/crates/rspack_plugin_css/src/runtime/mod.rs +++ b/crates/rspack_plugin_css/src/runtime/mod.rs @@ -48,8 +48,8 @@ impl RuntimeModule for CssLoadingRuntimeModule { && !matches!(has_css_matcher, BooleanMatcher::Condition(false)); let initial_chunks = chunk.get_all_initial_chunks(&compilation.chunk_group_by_ukey); - let mut initial_chunk_ids_with_css = HashSet::default(); - let mut initial_chunk_ids_without_css = HashSet::default(); + let mut initial_chunk_ids = HashSet::default(); + for chunk_ukey in initial_chunks.iter() { let id = compilation .chunk_by_ukey @@ -57,13 +57,11 @@ impl RuntimeModule for CssLoadingRuntimeModule { .expect_id() .to_string(); if chunk_has_css(chunk_ukey, compilation) { - initial_chunk_ids_with_css.insert(id); - } else { - initial_chunk_ids_without_css.insert(id); + initial_chunk_ids.insert(id); } } - if !with_hmr && !with_loading && initial_chunk_ids_with_css.is_empty() { + if !with_hmr && !with_loading { return Ok(RawSource::from("").boxed()); } @@ -76,7 +74,7 @@ impl RuntimeModule for CssLoadingRuntimeModule { // only render chunk without css. See packages/rspack/tests/runtimeCases/runtime/split-css-chunk test. source.add(RawSource::from(format!( "var installedChunks = {};\n", - &stringify_chunks(&initial_chunk_ids_without_css, 0) + &stringify_chunks(&initial_chunk_ids, 0) ))); let cross_origin_content = if let CrossOriginLoading::Enable(cross_origin) = @@ -99,88 +97,36 @@ impl RuntimeModule for CssLoadingRuntimeModule { let chunk_load_timeout = compilation.options.output.chunk_load_timeout.to_string(); let environment = &compilation.options.output.environment; - let with_compression = compilation.options.output.css_head_data_compression; let load_css_chunk_data = basic_function( environment, - "target, link, chunkId", + "target, chunkId", &format!( - r#"var data, token = "", token2 = "", token3 = "", exports = {{}}, composes = [], {}name = "--webpack-" + uniqueName + "-" + chunkId, i, cc = 1, composes = {{}}; -try {{ - if(!link) link = loadStylesheet(chunkId); - var cssRules = link.sheet.cssRules || link.sheet.rules; - var j = cssRules.length - 1; - while(j > -1 && !data) {{ - var style = cssRules[j--].style; - if(!style) continue; - data = style.getPropertyValue(name); - }} -}} catch(_) {{}} -if(!data) {{ - data = getComputedStyle(document.head).getPropertyValue(name); -}} -if(!data) return []; -{} -for(i = 0; cc; i++) {{ - cc = data.charCodeAt(i); - if(cc == 58) {{ token2 = token; token = ""; }} - else if(cc == 47) {{ token = token.replace(/^_/, ""); token2 = token2.replace(/^_/, ""); if (token3) {{ composes.push(token2, token3, token) }} else {{ exports[token2] = exports[token2] === undefined ? token : exports[token2] + " " + token }} token = ""; token2 = ""; token3 = "" }} - else if(cc == 38) {{ {}(exports); }} - else if(!cc || cc == 44) {{ token = token.replace(/^_/, ""); target[token] = ({}).bind(null, exports, composes); {}token = ""; token2 = ""; exports = {{}}; composes = [] }} - else if(cc == 92) {{ token += data[++i] }} - else if(cc == 64) {{ token3 = token; token = ""; }} - else {{ token += data[i]; }} -}} -{}installedChunks[chunkId] = 0; -{} -"#, - with_hmr.then_some("moduleIds = [], ").unwrap_or_default(), - if with_compression { - r#"var map = {}, char = data[0], oldPhrase = char, decoded = char, code = 256, maxCode = "\uffff".charCodeAt(0), phrase; - for (i = 1; i < data.length; i++) { - cc = data[i].charCodeAt(0); - if (cc < 256) phrase = data[i]; else phrase = map[cc] ? map[cc] : (oldPhrase + char); - decoded += phrase; - char = phrase.charAt(0); - map[code] = oldPhrase + char; - if (++code > maxCode) { code = 256; map = {}; } - oldPhrase = phrase; - } - data = decoded;"# - } else { - "// css head data compression is disabled" - }, - RuntimeGlobals::MAKE_NAMESPACE_OBJECT, - basic_function( - environment, - "exports, composes, module", - "handleCssComposes(exports, composes)\nmodule.exports = exports;" - ), - with_hmr - .then_some("moduleIds.push(token); ") - .unwrap_or_default(), + r#"{} +installedChunks[chunkId] = 0; +{}"#, with_hmr .then_some(format!( - "if(target == {})", + "var moduleIds = [];\nif(target == {})", RuntimeGlobals::MODULE_FACTORIES )) .unwrap_or_default(), - with_hmr.then_some("return moduleIds;").unwrap_or_default() + with_hmr.then_some("return moduleIds").unwrap_or_default(), ), ); - let load_initial_chunk_data = if initial_chunk_ids_with_css.len() > 2 { + let load_initial_chunk_data = if initial_chunk_ids.len() > 2 { Cow::Owned(format!( "[{}].forEach(loadCssChunkData.bind(null, {}, 0));", - initial_chunk_ids_with_css + initial_chunk_ids .iter() .map(|id| serde_json::to_string(id).expect("should ok to convert to string")) .collect::>() .join(","), RuntimeGlobals::MODULE_FACTORIES )) - } else if !initial_chunk_ids_with_css.is_empty() { + } else if !initial_chunk_ids.is_empty() { Cow::Owned( - initial_chunk_ids_with_css + initial_chunk_ids .iter() .map(|id| { let id = serde_json::to_string(id).expect("should ok to convert to string"); diff --git a/crates/rspack_plugin_hmr/Cargo.toml b/crates/rspack_plugin_hmr/Cargo.toml index a8394bd3820..903bafb0e09 100644 --- a/crates/rspack_plugin_hmr/Cargo.toml +++ b/crates/rspack_plugin_hmr/Cargo.toml @@ -11,6 +11,7 @@ rspack_collections = { version = "0.1.0", path = "../rspack_collections" } rspack_core = { version = "0.1.0", path = "../rspack_core" } rspack_error = { version = "0.1.0", path = "../rspack_error" } rspack_hook = { version = "0.1.0", path = "../rspack_hook" } +rspack_plugin_css = { version = "0.1.0", path = "../rspack_plugin_css" } rspack_plugin_javascript = { version = "0.1.0", path = "../rspack_plugin_javascript" } rspack_util = { version = "0.1.0", path = "../rspack_util" } diff --git a/crates/rspack_plugin_hmr/src/lib.rs b/crates/rspack_plugin_hmr/src/lib.rs index 7fac55bc58c..42f9c5a1be7 100644 --- a/crates/rspack_plugin_hmr/src/lib.rs +++ b/crates/rspack_plugin_hmr/src/lib.rs @@ -17,6 +17,7 @@ use rspack_core::{ }; use rspack_error::Result; use rspack_hook::{plugin, plugin_hook}; +use rspack_plugin_css::parser_and_generator::CssParserAndGenerator; use rspack_plugin_javascript::{ hot_module_replacement_plugin::{ ImportMetaHotReplacementParserPlugin, ModuleHotReplacementParserPlugin, @@ -373,7 +374,14 @@ fn normal_module_factory_parser( } else if module_type.is_js_esm() { parser.add_parser_plugin(Box::new(ImportMetaHotReplacementParserPlugin::new())); } + } else if matches!( + module_type, + ModuleType::Css | ModuleType::CssAuto | ModuleType::CssModule + ) && let Some(parser) = parser.downcast_mut::() + { + parser.hot = true; } + Ok(()) } diff --git a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap index 6224515c3ef..cf1c4a55818 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap @@ -6,14 +6,9 @@ body { color: #00f; } } - -head{--webpack--909:used:_-ec1c834aĊcc99e-ĀĂ/&_368;} `; -exports[`config config/builtin-lightningcss-loader/minify exported tests css content minifyed 1`] = ` -.foo{-webkit-transition:all Xs;transition:all Xs}.bar{padding:0} -head{--webpack--909:&_487;} -`; +exports[`config config/builtin-lightningcss-loader/minify exported tests css content minifyed 1`] = `.foo{-webkit-transition:all Xs;transition:all Xs}.bar{padding:0}`; exports[`config config/builtins/css-auto exported tests css/auto can handle css module correctly 1`] = ` Object { @@ -221,7 +216,6 @@ exports[`config config/chunk-index/available-modules-order-index exported tests .n { color: blue; } -head{--webpack--shared:&_547,Ā587;} `; exports[`config config/css/at-import-in-the-top exported tests at-import-in-the-top 1`] = ` @@ -243,8 +237,6 @@ exports[`config config/css/at-import-in-the-top exported tests at-import-in-the- .b { color: red; } - -head{--webpack--909:&_412,Ā645ą_34;} `; exports[`config config/css/export-selector exported tests should have correct css result 1`] = ` @@ -260,8 +252,6 @@ exports[`config config/css/export-selector exported tests should have correct cs /* #endregion "./style.module.css?imported" */ - -head{--webpack--imported_js:foo:foo/bar:b/ a/ r/local:local/dashName:dashName/&/.//style/.module/.css/?imported;} `; exports[`config config/css/rewrite-url exported tests should rewrite the css url() 1`] = `ac673538c200453e.png`; @@ -328,8 +318,6 @@ div { a143: url(data:image/svg+xml;charset=UTF-8,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!DOCTYPE%Xsvg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%0A%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%0A%09%20width%3D%22191px%22%20height%3D%22191px%22%20viewBox%3D%220%200%20191%20191%22%20enable-background%3D%22new%200%200%20191%20191%22%20xml%3Aspace%3D%22preserve%22%3E%0A%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M95.5%2C0C42.8%2C0%2C0%2C42.8%2C0%2C95.5S42.8%2C191%2C95.5%2C191S191%2C148.2%2C191%2C95.5S148.2%2C0%2C95.5%2C0z%20M95.5%2C187.6%0A%09c-50.848%2C0-92.1-41.25-92.1-92.1c0-50.848%2C41.252-92.1%2C92.1-92.1c50.85%2C0%2C92.1%2C41.252%2C92.1%2C92.1%0A%09C187.6%2C146.35%2C146.35%2C187.6%2C95.5%2C187.6z%22%2F%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M92.9%2C10v8.6H91v-6.5c-0.1%2C0.1-0.2%2C0.2-0.4%2C0.3c-0.2%2C0.1-0.3%2C0.2-0.4%2C0.2c-0.1%2C0-0.3%2C0.1-0.5%2C0.2%0A%09%09c-0.2%2C0.1-0.3%2C0.1-0.5%2C0.1v-1.6c0.5-0.1%2C0.9-0.3%2C1.4-0.5c0.5-0.2%2C0.8-0.5%2C1.2-0.7h1.1V10z%22%2F%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M97.1%2C17.1h3.602v1.5h-5.6V18c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.6%2C0.5-0.9c0.2-0.3%2C0.5-0.5%2C0.7-0.7%0A%09%09c0.2-0.2%2C0.5-0.4%2C0.7-0.6c0.199-0.2%2C0.5-0.3%2C0.6-0.5c0.102-0.2%2C0.301-0.3%2C0.5-0.5c0.2-0.2%2C0.2-0.3%2C0.301-0.5%0A%09%09c0.101-0.2%2C0.101-0.3%2C0.101-0.5c0-0.4-0.101-0.6-0.3-0.8c-0.2-0.2-0.4-0.3-0.801-0.3c-0.699%2C0-1.399%2C0.3-2.101%2C0.9v-1.6%0A%09%09c0.7-0.5%2C1.5-0.7%2C2.5-0.7c0.399%2C0%2C0.8%2C0.1%2C1.101%2C0.2c0.301%2C0.1%2C0.601%2C0.3%2C0.899%2C0.5c0.3%2C0.2%2C0.399%2C0.5%2C0.5%2C0.8%0A%09%09c0.101%2C0.3%2C0.2%2C0.6%2C0.2%2CXs-0.102%2C0.7-0.2%2C1c-0.099%2C0.3-0.3%2C0.6-0.5%2C0.8c-0.2%2C0.2-0.399%2C0.5-0.7%2C0.7c-0.3%2C0.2-0.5%2C0.4-0.8%2C0.6%0A%09%09c-0.2%2C0.1-0.399%2C0.3-0.5%2CXs-0.3%2C0.3-0.5%2CXs-0.2%2C0.3-0.3%2C0.4C97.1%2C17%2C97.1%2C17%2C97.1%2C17.1z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M15%2C95.4c0%2C0.7-0.1%2C1.4-0.2%2C2c-0.1%2C0.6-0.4%2C1.1-0.7%2C1.5C13.8%2C99.3%2C13.4%2C99.6%2C12.9%2CXs-1%2C0.3-1.5%2C0.3%0A%09%09c-0.7%2C0-1.3-0.1-1.8-0.3v-1.5c0.4%2C0.3%2C1%2C0.4%2C1.6%2C0.4c0.6%2C0%2C1.1-0.2%2C1.5-0.7c0.4-0.5%2C0.5-1.1%2C0.5-1.9l0%2C0%0A%09%09C12.8%2C96.7%2C12.3%2C96.9%2C11.5%2C96.9c-0.3%2C0-0.7-0.102-1-0.2c-0.3-0.101-0.5-0.3-0.8-0.5c-0.3-0.2-0.4-0.5-0.5-0.8%0A%09%09c-0.1-0.3-0.2-0.7-0.2-1c0-0.4%2C0.1-0.8%2C0.2-1.2c0.1-0.4%2C0.3-0.7%2C0.6-0.9c0.3-0.2%2C0.6-0.5%2C0.9-0.6c0.3-0.1%2C0.8-0.2%2C1.2-0.2%0A%09%09c0.5%2C0%2C0.9%2C0.1%2C1.2%2C0.3c0.3%2C0.2%2C0.7%2C0.4%2C0.9%2CXs0.5%2C0.7%2C0.6%2C1.2S15%2C94.8%2C15%2C95.4z%20M13.1%2C94.4c0-0.2%2C0-0.4-0.1-0.6%0A%09%09c-0.1-0.2-0.1-0.4-0.2-0.5c-0.1-0.1-0.2-0.2-0.4-0.3c-0.2-0.1-0.3-0.1-0.5-0.1c-0.2%2C0-0.3%2C0-0.4%2CXs-0.3%2C0.2-0.3%2C0.3%0A%09%09c0%2C0.1-0.2%2C0.3-0.2%2C0.4c0%2C0.1-0.1%2C0.4-0.1%2C0.6c0%2C0.2%2C0%2C0.4%2C0.1%2C0.6c0.1%2C0.2%2C0.1%2C0.3%2C0.2%2C0.4c0.1%2C0.1%2C0.2%2C0.2%2C0.4%2C0.3%0A%09%09c0.2%2C0.1%2C0.3%2C0.1%2C0.5%2C0.1c0.2%2C0%2C0.3%2C0%2C0.4-Xs0.2-0.2%2C0.3-0.3c0.1-0.1%2C0.2-0.2%2C0.2-0.4C13%2C94.7%2C13.1%2C94.6%2C13.1%2C94.4z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M176%2C99.7V98.1c0.6%2C0.4%2C1.2%2C0.602%2C2%2C0.602c0.5%2C0%2C0.8-0.102%2C1.1-0.301c0.301-0.199%2C0.4-0.5%2C0.4-0.801%0A%09%09c0-0.398-0.2-0.699-0.5-0.898c-0.3-0.2-0.8-0.301-1.3-0.301h-0.802V95h0.701c1.101%2C0%2C1.601-0.4%2C1.601-1.1c0-0.7-0.4-1-1.302-1%0A%09%09c-0.6%2C0-1.1%2C0.2-1.6%2C0.5v-1.5c0.6-0.3%2C1.301-0.4%2C2.1-0.4c0.9%2C0%2C1.5%2C0.2%2C2%2CXs0.701%2C0.9%2C0.701%2C1.5c0%2C1.1-0.601%2C1.8-1.701%2C2.1l0%2C0%0A%09%09c0.602%2C0.1%2C1.102%2C0.3%2C1.4%2CXs0.5%2C0.8%2C0.5%2C1.3c0%2C0.801-0.3%2C1.4-0.9%2C1.9c-0.6%2C0.5-1.398%2C0.7-2.398%2C0.7%0A%09%09C177.2%2C100.1%2C176.5%2C100%2C176%2C99.7z%22%2F%3E%0A%3C%2Fg%3E%0A%3Cg%3E%0A%09%3Cpath%20fill%3D%22%23636363%22%20d%3D%22M98.5%2C179.102c0%2C0.398-0.1%2C0.799-0.2%2C1.199C98.2%2C180.7%2C98%2C181%2C97.7%2CXs-0.601%2C0.5-0.9%2C0.601%0A%09%09c-0.3%2C0.1-0.7%2C0.199-1.2%2C0.199c-0.5%2C0-0.9-0.1-1.3-0.3c-0.4-0.2-0.7-0.399-0.9-0.8c-0.2-0.4-0.5-0.7-0.6-1.2%0A%09%09c-0.1-0.5-0.2-1-0.2-1.601c0-0.699%2C0.1-1.399%2C0.3-2c0.2-0.601%2C0.4-1.101%2C0.8-1.5c0.4-0.399%2C0.7-0.699%2C1.2-1c0.5-0.3%2C1-0.3%2C1.6-0.3%0A%09%09c0.6%2C0%2C1.2%2C0.101%2C1.5%2C0.199v1.5c-0.4-0.199-0.9-0.399-1.4-0.399c-0.3%2C0-0.6%2C0.101-0.8%2C0.2c-0.2%2C0.101-0.5%2C0.3-0.7%2C0.5%0A%09%09c-0.2%2C0.199-0.3%2C0.5-0.4%2C0.8c-0.1%2C0.301-0.2%2C0.7-0.2%2C1.101l0%2C0c0.4-0.601%2C1-0.8%2C1.8-0.8c0.3%2C0%2C0.7%2C0.1%2C0.9%2C0.199%0A%09%09c0.2%2C0.101%2C0.5%2C0.301%2C0.7%2C0.5c0.199%2C0.2%2C0.398%2C0.5%2C0.5%2C0.801C98.5%2C178.2%2C98.5%2C178.7%2C98.5%2C179.102z%20M96.7%2C179.2%0A%09%09c0-0.899-0.4-1.399-1.1-1.399c-0.2%2C0-0.3%2C0-0.5%2C0.1c-0.2%2C0.101-0.3%2C0.201-0.4%2C0.301c-0.1%2C0.101-0.2%2C0.199-0.2%2C0.4%0A%09%09c0%2C0.199-0.1%2C0.299-0.1%2C0.5c0%2C0.199%2C0%2C0.398%2C0.1%2CXs0.1%2C0.3%2C0.2%2C0.5c0.1%2C0.199%2C0.2%2C0.199%2C0.4%2C0.3c0.2%2C0.101%2C0.3%2C0.101%2C0.5%2C0.101%0A%09%09c0.2%2C0%2C0.3%2C0%2C0.5-0.101c0.2-0.101%2C0.301-0.199%2C0.301-0.3c0-0.1%2C0.199-0.301%2C0.199-0.399C96.6%2C179.7%2C96.7%2C179.4%2C96.7%2C179.2z%22%2F%3E%0A%3C%2Fg%3E%0A%3Ccircle%20fill%3D%22%23636363%22%20cx%3D%2295%22%20cy%3D%2295%22%20r%3D%227%22%2F%3E%0A%3C%2Fsvg%3E%0A) 50% 50%/191px no-repeat; } - -head{--webpack--120:&_13;} `; exports[`config config/externals/reexport-star exported tests reexport star from external module 1`] = ` @@ -768,6 +756,4 @@ exports[`config config/schemes/data-imports exported tests data imports 1`] = ` c: url(7159cadb6967ca3c); d: url(7159cadb6967ca3c); } - -head{--webpack--909:&_653,Ā47ĄĀ645ą_49Ď571;} `; diff --git a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap index d38a5fc93a3..e7a0f1f79d4 100644 --- a/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap +++ b/packages/rspack-test-tools/tests/__snapshots__/StatsOutput.test.js.snap @@ -85,13 +85,13 @@ Rspack x.x.x compiled successfully in X s `; exports[`statsOutput statsOutput/css-concat should print correct stats for 1`] = ` -asset main.js 7.8 KiB [emitted] (name: main) -asset main.css 51 bytes [emitted] (name: main) -Entrypoint main 7.85 KiB = main.js 7.8 KiB main.css 51 bytes -runtime modules 6.47 KiB 6 modules -cacheable modules 20 bytes (javascript) 23 bytes (css) +asset main.js 3.65 KiB [emitted] (name: main) +asset main.css 24 bytes [emitted] (name: main) +Entrypoint main 3.67 KiB = main.js 3.65 KiB main.css 24 bytes +runtime modules 2.26 KiB 6 modules +cacheable modules 62 bytes (javascript) 23 bytes (css) ./index.js 20 bytes [built] [code generated] - ./foo.css 23 bytes [built] [code generated] + ./foo.css 42 bytes (javascript) 23 bytes (css) [built] [code generated] Rspack x.x.x compiled successfully in X s `; @@ -106,8 +106,8 @@ Rspack x.x.x compiled successfully in X s `; exports[`statsOutput statsOutput/hot+production should print correct stats for 1`] = ` -asset main.js 35.5 KiB [emitted] (name: main) -runtime modules 33.1 KiB 12 modules +asset main.js 33.5 KiB [emitted] (name: main) +runtime modules 31.2 KiB 12 modules ./index.js 25 bytes [built] [code generated] Rspack x.x.x compiled successfully in X s `; diff --git a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt index 42efc0f9e75..6050878323d 100644 --- a/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt +++ b/packages/rspack-test-tools/tests/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt @@ -40,7 +40,7 @@ background: red; } -head{--webpack-__rspack_test__-main:f-1:\.\/_fĄmodule_ĄĆĈā--ē_d1fc8b18ab0f5133\<Ěf/făąćĉ.ċčďđıĔėćęěĝğġģĥħĩīěĮİēijĵĎĐĒIJĕĻ_ĽĜĞĠĢĤĦĨĪĬ/&ŏŋČōĄcss,dāʼnćdĊŢķŏęőĘc5e7cbb4cc9231c2Īŵe/dūęŮĶŎĹũŒ_ƆŸźżžƀƂƄ<ƆƈƊŭĴůƎēũ1ĖŴŶƔŻŽſƁƃƅŶŞŏƟŌďŤŦ,bŪűbƌōĸēƹƥƑf79ża5Ʈ<DŽ9/bƊƼƠƍƿćƹǃDžLJljƚnjǎǐƽŰĹǁƦļnjǙNJǜşıǑƴeƶŧchain2ƊstyƵǒƾűǰDzǴǣœdġȃ36bĦ19ĝe8Ŝġ/ǾdzǵƇȒǴūšƍǮ@ĭȖĂűǷǹǭǻǠēȞȁęȄ8ȆȈ1ȊȌȎīȐȞǶǸǺǬǔƒDZȓȨȃaȅȇȉȋ8ȍȏaȑȻnĂȕɉȟıșţ.ťsȜɈǿĂcɖdzɎĆƳơțd/root-claŦȵȢǟƢćɣɥɧɩŦȽȪȬɂȰɆɢɤɦɨɪsɬȷơȹȧƑȾɀȭȯɄȱȾɼɲɿɫȠȶȣȸǽɉ2ɶȿȫɁȮɃɅȲɇɱɾɴʁƇʣɳʀȘɮțĭʨʑʁəʯʥūɞȚɒŦ@ɡʳʪʢɽʩʒǪʬʸɔbƱıȡʃʷɓ;} + ``` ```js title=main.js @@ -52,6 +52,39 @@ __webpack_require__.r(__webpack_exports__); +}), +"./b.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { +__webpack_require__.r(module.exports = { + "b-1": "./_b.module_./_b-1--/__f794ca5c2Rspack App +Rspack App ``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/css/exports-convention-prod/webpack.config.js b/packages/rspack-test-tools/tests/configCases/css/exports-convention-prod/webpack.config.js index 57c5c0b4044..eb6eec54d8c 100644 --- a/packages/rspack-test-tools/tests/configCases/css/exports-convention-prod/webpack.config.js +++ b/packages/rspack-test-tools/tests/configCases/css/exports-convention-prod/webpack.config.js @@ -2,6 +2,7 @@ const common = { mode: "production", optimization: { moduleIds: "named", + concatenateModules: false }, module: { generator: { diff --git a/packages/rspack-test-tools/tests/configCases/web/fetch-priority/index.js b/packages/rspack-test-tools/tests/configCases/web/fetch-priority/index.js index 713be3088b6..7fde22bfcc3 100644 --- a/packages/rspack-test-tools/tests/configCases/web/fetch-priority/index.js +++ b/packages/rspack-test-tools/tests/configCases/web/fetch-priority/index.js @@ -78,10 +78,10 @@ it("should set fetchPriority", () => { expect(link1.getAttribute("fetchpriority")).toBe("high"); import("./style-1.css"); - const link2 = document.head.children[14]; + const link2 = document.head.children[15]; expect(link2.getAttribute("fetchpriority")).toBeFalsy(); import(/* webpackFetchPriority: "low" */ "./style-2.css"); - const link3 = document.head.children[15]; + const link3 = document.head.children[17]; expect(link3.getAttribute("fetchpriority")).toBe("low"); }); diff --git a/packages/rspack-test-tools/tests/configCases/web/nonce/index.js b/packages/rspack-test-tools/tests/configCases/web/nonce/index.js index 5f5c78d1c2c..ff1a6f7ffa2 100644 --- a/packages/rspack-test-tools/tests/configCases/web/nonce/index.js +++ b/packages/rspack-test-tools/tests/configCases/web/nonce/index.js @@ -17,7 +17,7 @@ it("should set nonce attributes", () => { import(/* webpackChunkName: "chunk-css" */ "./chunk.css"); - expect(document.head._children).toHaveLength(2); + expect(document.head._children).toHaveLength(3); const link = document.head._children[1]; diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt index 75e2a595f9d..f8cbb28133e 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 209 +- Update: main.LAST_HASH.hot-update.js, size: 365 ## Manifest @@ -23,7 +23,7 @@ ### main.LAST_HASH.hot-update.js #### Changed Modules - +- ./index.css #### Changed Runtime Modules - webpack/runtime/get_full_hash @@ -31,7 +31,15 @@ #### Changed Content ```js "use strict"; -self["webpackHotUpdatecss_test"]('main', {},function(__webpack_require__) { +self["webpackHotUpdatecss_test"]('main', { +"./index.css": (function (module, __unused_webpack_exports, __webpack_require__) { +__webpack_require__.r(module.exports = {}); +module.hot.accept(); + + +}), + +},function(__webpack_require__) { // webpack/runtime/get_full_hash (() => { __webpack_require__.h = function () { diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/test.config.js b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/test.config.js index 5424297748b..7ccc7bf8829 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/test.config.js +++ b/packages/rspack-test-tools/tests/hotCases/css/css-loading-unique-name/test.config.js @@ -1,3 +1,3 @@ module.exports = { - documentType: 'fake' + documentType: 'jsdom' } diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt index c9120446ae7..179bf4e072b 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/css-modules/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 375 +- Update: main.LAST_HASH.hot-update.js, size: 397 ## Manifest @@ -37,6 +37,8 @@ __webpack_require__.r(module.exports = { "a": "-_index_module_css-a", }); +module.hot.accept(); + }), diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-modules/index.js b/packages/rspack-test-tools/tests/hotCases/css/css-modules/index.js index da0b719cbc9..428d364119c 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-modules/index.js +++ b/packages/rspack-test-tools/tests/hotCases/css/css-modules/index.js @@ -1,11 +1,11 @@ import style from './index.module.css'; it("css modules hmr", (done) => { - expect(style.div).not.toBe(null); - module.hot.accept("./index.module.css", () => { - expect(style.a).not.toBe(null); + expect(style.div).toBeDefined(); + NEXT(require("../../update")(done, true, () => { + const style = require('./index.module.css') + expect(style.a).toBeDefined(); expect(style).not.toContain('div'); done(); - }); - NEXT(require("../../update")(done)); + })); }); diff --git a/packages/rspack-test-tools/tests/hotCases/css/css-modules/rspack.config.js b/packages/rspack-test-tools/tests/hotCases/css/css-modules/rspack.config.js index 396fc9da0dd..92fda519720 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/css-modules/rspack.config.js +++ b/packages/rspack-test-tools/tests/hotCases/css/css-modules/rspack.config.js @@ -4,17 +4,17 @@ module.exports = { main: './index.js', }, module: { - generator: { + parser: { 'css/module': { - exportsOnly: true + namedExports: false, } }, rules: [ { test: /\.module\.css$/, type: 'css/module', - parser: { - namedExports: false, + generator: { + exportsOnly: true } } ] diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/0.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/0.snap.txt deleted file mode 100644 index 8a4dc1e3b67..00000000000 --- a/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/0.snap.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Case css: Step 0 - -## Changed Files - - -## Asset Files -- Bundle: bundle.js - -## Manifest - - -## Update \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt deleted file mode 100644 index 10cde0fe32d..00000000000 --- a/packages/rspack-test-tools/tests/hotCases/css/css/__snapshots__/web/1.snap.txt +++ /dev/null @@ -1,45 +0,0 @@ -# Case css: Step 1 - -## Changed Files -- index.css - -## Asset Files -- Bundle: bundle.js -- Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 201 - -## Manifest - -### main.LAST_HASH.hot-update.json - -```json -{"c":["main"],"r":[],"m":[]} -``` - - -## Update - - -### main.LAST_HASH.hot-update.js - -#### Changed Modules - - -#### Changed Runtime Modules -- webpack/runtime/get_full_hash - -#### Changed Content -```js -"use strict"; -self["webpackHotUpdate"]('main', {},function(__webpack_require__) { -// webpack/runtime/get_full_hash -(() => { -__webpack_require__.h = function () { - return "CURRENT_HASH"; -}; - -})(); - -} -); -``` \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/index.css b/packages/rspack-test-tools/tests/hotCases/css/css/index.css deleted file mode 100644 index 3337fffe800..00000000000 --- a/packages/rspack-test-tools/tests/hotCases/css/css/index.css +++ /dev/null @@ -1,7 +0,0 @@ -body { - background-color: red; -} ---- -body { - background-color: yellow; -} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/index.js b/packages/rspack-test-tools/tests/hotCases/css/css/index.js deleted file mode 100644 index f9dcfccf6ef..00000000000 --- a/packages/rspack-test-tools/tests/hotCases/css/css/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import './index.css'; - -it("css hmr", (done) => { - if (__webpack_require__.hmrC.css) { - expect(document.head.children[0].href).toContain("bundle.css"); - } - NEXT(require("../../update")(done, true, () => { - if (__webpack_require__.hmrC.css) { - expect(document.head.children[0].href).toContain("bundle.css?hmr"); - } - done(); - })); -}); diff --git a/packages/rspack-test-tools/tests/hotCases/css/css/test.config.js b/packages/rspack-test-tools/tests/hotCases/css/css/test.config.js deleted file mode 100644 index 5424297748b..00000000000 --- a/packages/rspack-test-tools/tests/hotCases/css/css/test.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - documentType: 'fake' -} diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt index 759cbbec8f4..57d6357537d 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/__snapshots__/web/1.snap.txt @@ -6,7 +6,7 @@ ## Asset Files - Bundle: bundle.js - Manifest: main.LAST_HASH.hot-update.json, size: 28 -- Update: main.LAST_HASH.hot-update.js, size: 477 +- Update: main.LAST_HASH.hot-update.js, size: 499 ## Manifest @@ -38,6 +38,8 @@ __webpack_require__.r(module.exports = { "btnInfoIsEnabled": "./index.module.css__btn-info_is-enabled", }); +module.hot.accept(); + }), diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js index c9b9f020775..48e95bafedc 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/index.js @@ -2,9 +2,9 @@ import style from './index.module.css'; it("should store and resume css parser and generator states", (done) => { expect(style['btnInfoIsDisabled']).toBe('./index.module.css__btn-info_is-disabled'); - module.hot.accept("./index.module.css", () => { + NEXT(require("../../update")(done, true, () => { + const style = require('./index.module.css') expect(style['btnInfoIsEnabled']).toBe('./index.module.css__btn-info_is-enabled'); done(); - }); - NEXT(require("../../update")(done)); + })); }); diff --git a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/rspack.config.js b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/rspack.config.js index de99906d8dd..d1d39ff84df 100644 --- a/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/rspack.config.js +++ b/packages/rspack-test-tools/tests/hotCases/css/parser-and-generator-states/rspack.config.js @@ -1,17 +1,22 @@ /** @type {import("@rspack/core").Configuration} */ module.exports = { + entry: { + main: './index.js', + }, module: { + parser: { + 'css/module': { + namedExports: false, + } + }, rules: [ { - test: /\.css$/, + test: /\.module\.css$/, type: "css/module", - parser: { - namedExports: false, - }, generator: { exportsConvention: "camel-case", localIdentName: "[path][name][ext]__[local]", - exportsOnly: true + exportsOnly: true, }, } ] diff --git a/packages/rspack-test-tools/tests/treeShakingCases/css/__snapshots__/treeshaking.snap.txt b/packages/rspack-test-tools/tests/treeShakingCases/css/__snapshots__/treeshaking.snap.txt index 80964d47cfa..254112da4f9 100644 --- a/packages/rspack-test-tools/tests/treeShakingCases/css/__snapshots__/treeshaking.snap.txt +++ b/packages/rspack-test-tools/tests/treeShakingCases/css/__snapshots__/treeshaking.snap.txt @@ -9,6 +9,15 @@ _index_module_css__WEBPACK_IMPORTED_MODULE_0__.foo; _index_module_css__WEBPACK_IMPORTED_MODULE_0__.compose; +}), +"./index.module.css": (function (module, __unused_webpack_exports, __webpack_require__) { +module.exports = { + "foo": "__rspack_test__-ec1c834ac8cc99e-foo", + "bar": "__rspack_test__-ec1c834ac8cc99e-bar", + "compose": "__rspack_test__-ec1c834ac8cc99e-compose" + " " + "__rspack_test__-ec1c834ac8cc99e-bar", +}; + + }), },function(__webpack_require__) { diff --git a/tests/webpack-test/configCases/css/basic/test.config.js b/tests/webpack-test/configCases/css/basic/test.config.js index 0590757288f..504f8b6b77d 100644 --- a/tests/webpack-test/configCases/css/basic/test.config.js +++ b/tests/webpack-test/configCases/css/basic/test.config.js @@ -1,4 +1,7 @@ module.exports = { + findBundle: function (i, options) { + return ["style2_css.bundle0.js", "bundle0.js"]; + }, moduleScope(scope) { const link = scope.window.document.createElement("link"); link.rel = "stylesheet"; diff --git a/tests/webpack-test/configCases/css/conflicting-order/test.config.js b/tests/webpack-test/configCases/css/conflicting-order/test.config.js new file mode 100644 index 00000000000..9cebb39902e --- /dev/null +++ b/tests/webpack-test/configCases/css/conflicting-order/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["css.bundle0.js", "lazy4_js.bundle0.js", "bundle0.js"]; + } +}; diff --git a/tests/webpack-test/configCases/css/css-modules/test.config.js b/tests/webpack-test/configCases/css/css-modules/test.config.js new file mode 100644 index 00000000000..c2d4b42c6b9 --- /dev/null +++ b/tests/webpack-test/configCases/css/css-modules/test.config.js @@ -0,0 +1,7 @@ +module.exports = { + findBundle: function (i, options) { + return i === 0 + ? ["./use-style_js.bundle0.js", "./bundle0.js"] + : ["./142.bundle1.js", "./bundle1.js"]; + } +}; diff --git a/tests/webpack-test/configCases/css/exports-in-node/index.js b/tests/webpack-test/configCases/css/exports-in-node/index.js index 0c59f3e16d2..8e3b516c32c 100644 --- a/tests/webpack-test/configCases/css/exports-in-node/index.js +++ b/tests/webpack-test/configCases/css/exports-in-node/index.js @@ -1,6 +1,6 @@ -import * as style from "../exports/style.module.css?ns"; -import { a, abc } from "../exports/style.module.css?picked"; -import def from "../exports/style.module.css?default"; +import * as style from "../pseudo-export/style.module.css?ns"; +import { a, abc } from "../pseudo-export/style.module.css?picked"; +import def from "../pseudo-export/style.module.css?default"; it("should allow to import a css module", () => { expect(style).toEqual( diff --git a/tests/webpack-test/configCases/css/exports-in-node/test.filter.js b/tests/webpack-test/configCases/css/exports-in-node/test.filter.js new file mode 100644 index 00000000000..30ee57988c4 --- /dev/null +++ b/tests/webpack-test/configCases/css/exports-in-node/test.filter.js @@ -0,0 +1,2 @@ +// css-lexer cannot parse invalidate css comments +module.exports = () => false diff --git a/tests/webpack-test/configCases/css/external/test.config.js b/tests/webpack-test/configCases/css/external/test.config.js new file mode 100644 index 00000000000..66b963ff668 --- /dev/null +++ b/tests/webpack-test/configCases/css/external/test.config.js @@ -0,0 +1,5 @@ +module.exports = { + findBundle: function (i, options) { + return ["14.bundle0.js", "bundle0.js"]; + } +}; diff --git a/tests/webpack-test/configCases/css/large/index.js b/tests/webpack-test/configCases/css/large/index.js index 27d0c33caaa..5af05d909af 100644 --- a/tests/webpack-test/configCases/css/large/index.js +++ b/tests/webpack-test/configCases/css/large/index.js @@ -2,7 +2,7 @@ const prod = process.env.NODE_ENV === "production"; it("should allow to create css modules", done => { prod - ? __non_webpack_require__("./196.bundle1.js") + ? __non_webpack_require__("./use-style_js.bundle1.js") : __non_webpack_require__("./use-style_js.bundle0.js"); import("./use-style.js").then(({ default: x }) => { try { @@ -15,5 +15,8 @@ it("should allow to create css modules", done => { }); it("should allow to process tailwind as global css", done => { + prod + ? __non_webpack_require__("./tailwind_min_css.bundle1.js") + : __non_webpack_require__("./tailwind_min_css.bundle0.js"); import("./tailwind.min.css").then(() => done(), done); }); diff --git a/tests/webpack-test/configCases/css/large/webpack.config.js b/tests/webpack-test/configCases/css/large/webpack.config.js index 02d72e0652c..58ee296cf4a 100644 --- a/tests/webpack-test/configCases/css/large/webpack.config.js +++ b/tests/webpack-test/configCases/css/large/webpack.config.js @@ -6,6 +6,9 @@ module.exports = [ output: { uniqueName: "my-app" }, + optimization: { + chunkIds: 'named' + }, experiments: { css: true } @@ -13,6 +16,9 @@ module.exports = [ { target: "web", mode: "production", + optimization: { + chunkIds: 'named' + }, performance: false, experiments: { css: true diff --git a/tests/webpack-test/configCases/css/exports/imported.js b/tests/webpack-test/configCases/css/pseudo-export/imported.js similarity index 100% rename from tests/webpack-test/configCases/css/exports/imported.js rename to tests/webpack-test/configCases/css/pseudo-export/imported.js diff --git a/tests/webpack-test/configCases/css/exports/index.js b/tests/webpack-test/configCases/css/pseudo-export/index.js similarity index 73% rename from tests/webpack-test/configCases/css/exports/index.js rename to tests/webpack-test/configCases/css/pseudo-export/index.js index b65dc05aee5..a5544176023 100644 --- a/tests/webpack-test/configCases/css/exports/index.js +++ b/tests/webpack-test/configCases/css/pseudo-export/index.js @@ -1,12 +1,13 @@ it("should allow to dynamic import a css module", done => { + __non_webpack_require__("./style_module_css.bundle0.js"); import("./style.module.css").then(x => { try { expect(x).toEqual( nsObj({ a: "a", abc: "a b c", - comments: "abc def", - "white space": "abc\n\tdef", + comments: "abc/****/ /* hello world *//****/ def", + whitespace: "abc\n\tdef", default: "default" }) ); @@ -25,8 +26,8 @@ it("should allow to reexport a css module", done => { nsObj({ a: "a", abc: "a b c", - comments: "abc def", - "white space": "abc\n\tdef" + comments: "abc/****/ /* hello world *//****/ def", + whitespace: "abc\n\tdef" }) ); } catch (e) { @@ -44,8 +45,8 @@ it("should allow to import a css module", done => { nsObj({ a: "a", abc: "a b c", - comments: "abc def", - "white space": "abc\n\tdef", + comments: "abc/****/ /* hello world *//****/ def", + whitespace: "abc\n\tdef", default: "default" }) ); diff --git a/tests/webpack-test/configCases/css/exports/reexported.js b/tests/webpack-test/configCases/css/pseudo-export/reexported.js similarity index 100% rename from tests/webpack-test/configCases/css/exports/reexported.js rename to tests/webpack-test/configCases/css/pseudo-export/reexported.js diff --git a/tests/webpack-test/configCases/css/exports/style.module.css b/tests/webpack-test/configCases/css/pseudo-export/style.module.css similarity index 92% rename from tests/webpack-test/configCases/css/exports/style.module.css rename to tests/webpack-test/configCases/css/pseudo-export/style.module.css index c64b4ff9a64..24f1786c047 100644 --- a/tests/webpack-test/configCases/css/exports/style.module.css +++ b/tests/webpack-test/configCases/css/pseudo-export/style.module.css @@ -13,7 +13,7 @@ { - white space + whitespace : diff --git a/tests/webpack-test/configCases/css/pseudo-export/test.filter.js b/tests/webpack-test/configCases/css/pseudo-export/test.filter.js new file mode 100644 index 00000000000..30ee57988c4 --- /dev/null +++ b/tests/webpack-test/configCases/css/pseudo-export/test.filter.js @@ -0,0 +1,2 @@ +// css-lexer cannot parse invalidate css comments +module.exports = () => false diff --git a/tests/webpack-test/configCases/css/exports/webpack.config.js b/tests/webpack-test/configCases/css/pseudo-export/webpack.config.js similarity index 63% rename from tests/webpack-test/configCases/css/exports/webpack.config.js rename to tests/webpack-test/configCases/css/pseudo-export/webpack.config.js index 716ccc704ee..cfb8e5c0346 100644 --- a/tests/webpack-test/configCases/css/exports/webpack.config.js +++ b/tests/webpack-test/configCases/css/pseudo-export/webpack.config.js @@ -1,4 +1,4 @@ -/** @type {import("@rspack/core").Configuration} */ +/** @type {import("../../../../").Configuration} */ module.exports = { target: "web", mode: "development",