Unverified Commit 73efa184 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: don't generate CSS for Node.js (#75117)

parent ab874537
This diff is collapsed.
...@@ -2,14 +2,15 @@ use std::collections::HashMap; ...@@ -2,14 +2,15 @@ use std::collections::HashMap;
use anyhow::Result; use anyhow::Result;
use next_core::{ use next_core::{
self, next_client_reference::EcmascriptClientReferenceModule, self,
next_client_reference::{CssClientReferenceModule, EcmascriptClientReferenceModule},
next_server_component::server_component_module::NextServerComponentModule, next_server_component::server_component_module::NextServerComponentModule,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs, NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc,
}; };
use turbopack::css::CssModuleAsset; use turbopack::css::chunk::CssChunkPlaceable;
use turbopack_core::{module::Module, module_graph::SingleModuleGraph}; use turbopack_core::{module::Module, module_graph::SingleModuleGraph};
#[derive( #[derive(
...@@ -20,7 +21,7 @@ pub enum ClientReferenceMapType { ...@@ -20,7 +21,7 @@ pub enum ClientReferenceMapType {
module: ResolvedVc<EcmascriptClientReferenceModule>, module: ResolvedVc<EcmascriptClientReferenceModule>,
ssr_module: ResolvedVc<Box<dyn Module>>, ssr_module: ResolvedVc<Box<dyn Module>>,
}, },
CssClientReference(ResolvedVc<CssModuleAsset>), CssClientReference(ResolvedVc<Box<dyn CssChunkPlaceable>>),
ServerComponent(ResolvedVc<NextServerComponentModule>), ServerComponent(ResolvedVc<NextServerComponentModule>),
} }
...@@ -38,7 +39,7 @@ pub async fn map_client_references( ...@@ -38,7 +39,7 @@ pub async fn map_client_references(
let module = node.module; let module = node.module;
if let Some(client_reference_module) = if let Some(client_reference_module) =
ResolvedVc::try_downcast_type::<EcmascriptClientReferenceModule>(module).await? ResolvedVc::try_downcast_type_sync::<EcmascriptClientReferenceModule>(module)
{ {
Ok(Some(( Ok(Some((
module, module,
...@@ -47,15 +48,17 @@ pub async fn map_client_references( ...@@ -47,15 +48,17 @@ pub async fn map_client_references(
ssr_module: ResolvedVc::upcast(client_reference_module.await?.ssr_module), ssr_module: ResolvedVc::upcast(client_reference_module.await?.ssr_module),
}, },
))) )))
} else if let Some(css_client_reference_asset) = } else if let Some(client_reference_module) =
ResolvedVc::try_downcast_type::<CssModuleAsset>(module).await? ResolvedVc::try_downcast_type_sync::<CssClientReferenceModule>(module)
{ {
Ok(Some(( Ok(Some((
module, module,
ClientReferenceMapType::CssClientReference(css_client_reference_asset), ClientReferenceMapType::CssClientReference(ResolvedVc::upcast(
client_reference_module.await?.client_module,
)),
))) )))
} else if let Some(server_component) = } else if let Some(server_component) =
ResolvedVc::try_downcast_type::<NextServerComponentModule>(module).await? ResolvedVc::try_downcast_type_sync::<NextServerComponentModule>(module)
{ {
Ok(Some(( Ok(Some((
module, module,
......
...@@ -1211,7 +1211,7 @@ impl Project { ...@@ -1211,7 +1211,7 @@ impl Project {
transitions.push(( transitions.push((
ECMASCRIPT_CLIENT_TRANSITION_NAME.into(), ECMASCRIPT_CLIENT_TRANSITION_NAME.into(),
app_project app_project
.edge_client_reference_transition() .edge_ecmascript_client_reference_transition()
.to_resolved() .to_resolved()
.await?, .await?,
)); ));
...@@ -1297,7 +1297,7 @@ impl Project { ...@@ -1297,7 +1297,7 @@ impl Project {
transitions.push(( transitions.push((
ECMASCRIPT_CLIENT_TRANSITION_NAME.into(), ECMASCRIPT_CLIENT_TRANSITION_NAME.into(),
app_project app_project
.client_reference_transition() .ecmascript_client_reference_transition()
.to_resolved() .to_resolved()
.await?, .await?,
)); ));
...@@ -1352,7 +1352,7 @@ impl Project { ...@@ -1352,7 +1352,7 @@ impl Project {
transitions.push(( transitions.push((
ECMASCRIPT_CLIENT_TRANSITION_NAME.into(), ECMASCRIPT_CLIENT_TRANSITION_NAME.into(),
app_project app_project
.edge_client_reference_transition() .edge_ecmascript_client_reference_transition()
.to_resolved() .to_resolved()
.await?, .await?,
)); ));
......
...@@ -104,9 +104,12 @@ pub async fn get_app_client_references_chunks( ...@@ -104,9 +104,12 @@ pub async fn get_app_client_references_chunks(
}, },
) )
} }
ClientReferenceType::CssClientReference(css_module) => { ClientReferenceType::CssClientReference(css_client_reference) => {
let client_chunk_group = client_chunking_context let client_chunk_group = client_chunking_context
.root_chunk_group(*ResolvedVc::upcast(css_module), module_graph) .root_chunk_group(
*ResolvedVc::upcast(css_client_reference),
module_graph,
)
.await?; .await?;
( (
...@@ -226,13 +229,11 @@ pub async fn get_app_client_references_chunks( ...@@ -226,13 +229,11 @@ pub async fn get_app_client_references_chunks(
Ok(match client_reference_ty { Ok(match client_reference_ty {
ClientReferenceType::EcmascriptClientReference( ClientReferenceType::EcmascriptClientReference(
ecmascript_client_reference, ecmascript_client_reference,
) => { ) => *ResolvedVc::upcast(
let ecmascript_client_reference_ref = ecmascript_client_reference.await?.client_module,
ecmascript_client_reference.await?; ),
*ResolvedVc::upcast(ecmascript_client_reference_ref.client_module) ClientReferenceType::CssClientReference(css_client_reference) => {
} *ResolvedVc::upcast(*css_client_reference)
ClientReferenceType::CssClientReference(css_module) => {
*ResolvedVc::upcast(*css_module)
} }
}) })
}) })
......
use anyhow::{bail, Result};
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueToString, Vc};
use turbopack::css::chunk::CssChunkPlaceable;
use turbopack_core::{
asset::{Asset, AssetContent},
chunk::{ChunkGroupType, ChunkableModuleReference, ChunkingType, ChunkingTypeOption},
ident::AssetIdent,
module::Module,
reference::{ModuleReference, ModuleReferences},
resolve::ModuleResolveResult,
};
/// A [`CssClientReferenceModule`] is a marker module used to indicate which
/// client reference should appear in the client reference manifest.
#[turbo_tasks::value]
pub struct CssClientReferenceModule {
/// The CSS module (in the client context)
pub client_module: ResolvedVc<Box<dyn CssChunkPlaceable>>,
}
#[turbo_tasks::value_impl]
impl CssClientReferenceModule {
/// Create a new [`CssClientReferenceModule`] from the given source CSS
/// module.
#[turbo_tasks::function]
pub fn new(
client_module: ResolvedVc<Box<dyn CssChunkPlaceable>>,
) -> Vc<CssClientReferenceModule> {
CssClientReferenceModule { client_module }.cell()
}
}
#[turbo_tasks::function]
fn css_client_reference_modifier() -> Vc<RcStr> {
Vc::cell("css client reference".into())
}
#[turbo_tasks::value_impl]
impl Module for CssClientReferenceModule {
#[turbo_tasks::function]
fn ident(&self) -> Vc<AssetIdent> {
self.client_module
.ident()
.with_modifier(css_client_reference_modifier())
}
#[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> {
let CssClientReferenceModule { client_module, .. } = &*self.await?;
Ok(Vc::cell(vec![ResolvedVc::upcast(
CssClientReference::new(*ResolvedVc::upcast(*client_module))
.to_resolved()
.await?,
)]))
}
}
#[turbo_tasks::value_impl]
impl Asset for CssClientReferenceModule {
#[turbo_tasks::function]
fn content(&self) -> Result<Vc<AssetContent>> {
// The client reference asset only serves as a marker asset.
bail!("CssClientReferenceModule has no content")
}
}
#[turbo_tasks::value]
pub(crate) struct CssClientReference {
module: ResolvedVc<Box<dyn Module>>,
}
#[turbo_tasks::value_impl]
impl CssClientReference {
#[turbo_tasks::function]
pub fn new(module: ResolvedVc<Box<dyn Module>>) -> Vc<Self> {
Self::cell(CssClientReference { module })
}
}
#[turbo_tasks::value_impl]
impl ChunkableModuleReference for CssClientReference {
#[turbo_tasks::function]
fn chunking_type(&self) -> Vc<ChunkingTypeOption> {
Vc::cell(Some(ChunkingType::Isolated {
_ty: ChunkGroupType::Evaluated,
merge_tag: Some("client".into()),
}))
}
}
#[turbo_tasks::value_impl]
impl ModuleReference for CssClientReference {
#[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> {
ModuleResolveResult::module(self.module).cell()
}
}
#[turbo_tasks::value_impl]
impl ValueToString for CssClientReference {
#[turbo_tasks::function]
fn to_string(&self) -> Vc<RcStr> {
Vc::cell("css client reference to client".into())
}
}
use anyhow::{Context, Result};
use turbo_tasks::{ResolvedVc, Value, Vc};
use turbopack::{css::chunk::CssChunkPlaceable, transition::Transition, ModuleAssetContext};
use turbopack_core::{context::ProcessResult, reference_type::ReferenceType, source::Source};
use crate::next_client_reference::css_client_reference::css_client_reference_module::CssClientReferenceModule;
#[turbo_tasks::value(shared)]
pub struct NextCssClientReferenceTransition {
client_transition: ResolvedVc<Box<dyn Transition>>,
}
#[turbo_tasks::value_impl]
impl NextCssClientReferenceTransition {
#[turbo_tasks::function]
pub fn new(client_transition: ResolvedVc<Box<dyn Transition>>) -> Vc<Self> {
NextCssClientReferenceTransition { client_transition }.cell()
}
}
#[turbo_tasks::value_impl]
impl Transition for NextCssClientReferenceTransition {
#[turbo_tasks::function]
async fn process(
self: Vc<Self>,
source: Vc<Box<dyn Source>>,
rsc_module_asset_context: Vc<ModuleAssetContext>,
reference_type: Value<ReferenceType>,
) -> Result<Vc<ProcessResult>> {
let module =
self.await?
.client_transition
.process(source, rsc_module_asset_context, reference_type);
let ProcessResult::Module(module) = *module.await? else {
return Ok(ProcessResult::Ignore.cell());
};
let client_module = ResolvedVc::try_sidecast_sync::<Box<dyn CssChunkPlaceable>>(module)
.context("css client asset is not css chunk placeable")?;
Ok(ProcessResult::Module(ResolvedVc::upcast(
CssClientReferenceModule::new(*client_module)
.to_resolved()
.await?,
))
.cell())
}
}
pub(crate) mod css_client_reference_module;
pub(crate) mod css_client_reference_transition;
use anyhow::{bail, Result}; use anyhow::{bail, Result};
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Value, Vc}; use turbo_tasks::{ResolvedVc, Value, Vc};
use turbopack::{ use turbopack::{transition::Transition, ModuleAssetContext};
transition::{ContextTransition, Transition},
ModuleAssetContext,
};
use turbopack_core::{ use turbopack_core::{
context::ProcessResult, context::ProcessResult,
file_source::FileSource, file_source::FileSource,
...@@ -18,7 +15,7 @@ use crate::next_client_reference::ecmascript_client_reference::ecmascript_client ...@@ -18,7 +15,7 @@ use crate::next_client_reference::ecmascript_client_reference::ecmascript_client
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct NextEcmascriptClientReferenceTransition { pub struct NextEcmascriptClientReferenceTransition {
client_transition: ResolvedVc<Box<dyn Transition>>, client_transition: ResolvedVc<Box<dyn Transition>>,
ssr_transition: ResolvedVc<ContextTransition>, ssr_transition: ResolvedVc<Box<dyn Transition>>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
...@@ -26,7 +23,7 @@ impl NextEcmascriptClientReferenceTransition { ...@@ -26,7 +23,7 @@ impl NextEcmascriptClientReferenceTransition {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new( pub fn new(
client_transition: ResolvedVc<Box<dyn Transition>>, client_transition: ResolvedVc<Box<dyn Transition>>,
ssr_transition: ResolvedVc<ContextTransition>, ssr_transition: ResolvedVc<Box<dyn Transition>>,
) -> Vc<Self> { ) -> Vc<Self> {
NextEcmascriptClientReferenceTransition { NextEcmascriptClientReferenceTransition {
client_transition, client_transition,
......
pub(crate) mod css_client_reference;
pub(crate) mod ecmascript_client_reference; pub(crate) mod ecmascript_client_reference;
pub(crate) mod visit_client_reference; pub(crate) mod visit_client_reference;
pub use css_client_reference::{
css_client_reference_module::CssClientReferenceModule,
css_client_reference_transition::NextCssClientReferenceTransition,
};
pub use ecmascript_client_reference::{ pub use ecmascript_client_reference::{
ecmascript_client_reference_module::EcmascriptClientReferenceModule, ecmascript_client_reference_module::EcmascriptClientReferenceModule,
ecmascript_client_reference_transition::NextEcmascriptClientReferenceTransition, ecmascript_client_reference_transition::NextEcmascriptClientReferenceTransition,
......
...@@ -11,11 +11,14 @@ use turbo_tasks::{ ...@@ -11,11 +11,14 @@ use turbo_tasks::{
FxIndexMap, FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc, FxIndexMap, FxIndexSet, NonLocalValue, ReadRef, ResolvedVc, TryJoinIterExt, ValueToString, Vc,
}; };
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack::css::CssModuleAsset; use turbopack::css::chunk::CssChunkPlaceable;
use turbopack_core::{module::Module, reference::primary_referenced_modules}; use turbopack_core::{module::Module, reference::primary_referenced_modules};
use crate::{ use crate::{
next_client_reference::ecmascript_client_reference::ecmascript_client_reference_module::EcmascriptClientReferenceModule, next_client_reference::{
ecmascript_client_reference::ecmascript_client_reference_module::EcmascriptClientReferenceModule,
CssClientReferenceModule,
},
next_server_component::server_component_module::NextServerComponentModule, next_server_component::server_component_module::NextServerComponentModule,
next_server_utility::server_utility_module::NextServerUtilityModule, next_server_utility::server_utility_module::NextServerUtilityModule,
}; };
...@@ -63,7 +66,7 @@ impl ClientReference { ...@@ -63,7 +66,7 @@ impl ClientReference {
)] )]
pub enum ClientReferenceType { pub enum ClientReferenceType {
EcmascriptClientReference(ResolvedVc<EcmascriptClientReferenceModule>), EcmascriptClientReference(ResolvedVc<EcmascriptClientReferenceModule>),
CssClientReference(ResolvedVc<CssModuleAsset>), CssClientReference(ResolvedVc<Box<dyn CssChunkPlaceable>>),
} }
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
...@@ -420,8 +423,8 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference { ...@@ -420,8 +423,8 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
}); });
} }
if let Some(css_client_reference_asset) = if let Some(client_reference_module) =
ResolvedVc::try_downcast_type::<CssModuleAsset>(*module).await? ResolvedVc::try_downcast_type::<CssClientReferenceModule>(*module).await?
{ {
return Ok(VisitClientReferenceNode { return Ok(VisitClientReferenceNode {
state: node.state, state: node.state,
...@@ -429,10 +432,10 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference { ...@@ -429,10 +432,10 @@ impl Visit<VisitClientReferenceNode> for VisitClientReference {
ClientReference { ClientReference {
server_component: node.state.server_component(), server_component: node.state.server_component(),
ty: ClientReferenceType::CssClientReference( ty: ClientReferenceType::CssClientReference(
css_client_reference_asset, client_reference_module.await?.client_module,
), ),
}, },
css_client_reference_asset.ident().to_string().await?, client_reference_module.ident().to_string().await?,
), ),
}); });
} }
......
...@@ -2,7 +2,7 @@ use anyhow::Result; ...@@ -2,7 +2,7 @@ use anyhow::Result;
use next_custom_transforms::transforms::strip_page_exports::ExportFilter; use next_custom_transforms::transforms::strip_page_exports::ExportFilter;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, Vc}; use turbo_tasks::{ResolvedVc, Vc};
use turbopack::module_options::ModuleRule; use turbopack::module_options::{ModuleRule, ModuleRuleEffect, RuleCondition};
use crate::{ use crate::{
mode::NextMode, mode::NextMode,
...@@ -48,6 +48,27 @@ pub async fn get_next_server_transforms_rules( ...@@ -48,6 +48,27 @@ pub async fn get_next_server_transforms_rules(
} }
rules.push(get_next_font_transform_rule(mdx_rs)); rules.push(get_next_font_transform_rule(mdx_rs));
if !matches!(context_ty, ServerContextType::AppRSC { .. }) {
rules.extend([
// Ignore the internal ModuleCssAsset -> CssModuleAsset references
// The CSS Module module itself is still needed for class names
ModuleRule::new_internal(
RuleCondition::ResourcePathEndsWith(".module.css".into()),
vec![ModuleRuleEffect::Ignore],
),
]);
rules.extend([
// Ignore all non-module CSS references
ModuleRule::new(
RuleCondition::all(vec![
RuleCondition::ResourcePathEndsWith(".css".into()),
RuleCondition::not(RuleCondition::ResourcePathEndsWith(".module.css".into())),
]),
vec![ModuleRuleEffect::Ignore],
),
]);
}
if !foreign_code { if !foreign_code {
rules.push(get_next_page_static_info_assert_rule( rules.push(get_next_page_static_info_assert_rule(
mdx_rs, mdx_rs,
......
...@@ -167,13 +167,13 @@ impl ImportContext { ...@@ -167,13 +167,13 @@ impl ImportContext {
#[derive(Debug, Clone, Hash)] #[derive(Debug, Clone, Hash)]
pub enum CssReferenceSubType { pub enum CssReferenceSubType {
AtImport(Option<ResolvedVc<ImportContext>>), AtImport(Option<ResolvedVc<ImportContext>>),
/// Reference from ModuleCssAsset to an imported ModuleCssAsset for retrieving the composed
/// class name
Compose, Compose,
/// Reference from any asset to a CSS-parseable asset. /// Reference from ModuleCssAsset to the CssModuleAsset
///
/// This marks the boundary between non-CSS and CSS assets. The Next.js App
/// Router implementation uses this to inject client references in-between
/// Global/Module CSS assets and the underlying CSS assets.
Internal, Internal,
/// Used for generating the list of classes in a ModuleCssAsset
Analyze,
Custom(u8), Custom(u8),
Undefined, Undefined,
} }
......
...@@ -86,7 +86,14 @@ impl Module for ModuleCssAsset { ...@@ -86,7 +86,14 @@ impl Module for ModuleCssAsset {
.await? .await?
.iter() .iter()
.copied() .copied()
.chain(match *self.inner().try_into_module().await? { .chain(
match *self
.inner(Value::new(ReferenceType::Css(
CssReferenceSubType::Internal,
)))
.try_into_module()
.await?
{
Some(inner) => Some( Some(inner) => Some(
InternalCssAssetReference::new(*inner) InternalCssAssetReference::new(*inner)
.to_resolved() .to_resolved()
...@@ -94,7 +101,8 @@ impl Module for ModuleCssAsset { ...@@ -94,7 +101,8 @@ impl Module for ModuleCssAsset {
.map(ResolvedVc::upcast)?, .map(ResolvedVc::upcast)?,
), ),
None => None, None => None,
}) },
)
.collect(); .collect();
Ok(Vc::cell(references)) Ok(Vc::cell(references))
...@@ -156,16 +164,16 @@ struct ModuleCssClasses(FxIndexMap<String, Vec<ModuleCssClass>>); ...@@ -156,16 +164,16 @@ struct ModuleCssClasses(FxIndexMap<String, Vec<ModuleCssClass>>);
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ModuleCssAsset { impl ModuleCssAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
fn inner(&self) -> Vc<ProcessResult> { pub fn inner(&self, ty: Value<ReferenceType>) -> Vc<ProcessResult> {
self.asset_context.process( self.asset_context
*self.source, .process(*self.source, Value::new(ty.into_value()))
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)),
)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn classes(self: Vc<Self>) -> Result<Vc<ModuleCssClasses>> { async fn classes(self: Vc<Self>) -> Result<Vc<ModuleCssClasses>> {
let inner = self.inner().module(); let inner = self
.inner(Value::new(ReferenceType::Css(CssReferenceSubType::Analyze)))
.module();
let inner = Vc::try_resolve_sidecast::<Box<dyn ProcessCss>>(inner) let inner = Vc::try_resolve_sidecast::<Box<dyn ProcessCss>>(inner)
.await? .await?
......
...@@ -231,17 +231,12 @@ async fn apply_module_type( ...@@ -231,17 +231,12 @@ async fn apply_module_type(
} }
ModuleType::Json => ResolvedVc::upcast(JsonModuleAsset::new(*source).to_resolved().await?), ModuleType::Json => ResolvedVc::upcast(JsonModuleAsset::new(*source).to_resolved().await?),
ModuleType::Raw => ResolvedVc::upcast(RawModule::new(*source).to_resolved().await?), ModuleType::Raw => ResolvedVc::upcast(RawModule::new(*source).to_resolved().await?),
ModuleType::CssGlobal => {
return Ok(module_asset_context.process(
*source,
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)),
))
}
ModuleType::CssModule => ResolvedVc::upcast( ModuleType::CssModule => ResolvedVc::upcast(
ModuleCssAsset::new(*source, Vc::upcast(module_asset_context)) ModuleCssAsset::new(*source, Vc::upcast(module_asset_context))
.to_resolved() .to_resolved()
.await?, .await?,
), ),
ModuleType::Css { ty } => ResolvedVc::upcast( ModuleType::Css { ty } => ResolvedVc::upcast(
CssModuleAsset::new( CssModuleAsset::new(
*source, *source,
...@@ -541,6 +536,9 @@ async fn process_default_internal( ...@@ -541,6 +536,9 @@ async fn process_default_internal(
if rule.matches(source, &path_ref, &reference_type).await? { if rule.matches(source, &path_ref, &reference_type).await? {
for effect in rule.effects() { for effect in rule.effects() {
match effect { match effect {
ModuleRuleEffect::Ignore => {
return Ok(ProcessResult::Ignore.cell());
}
ModuleRuleEffect::SourceTransforms(transforms) => { ModuleRuleEffect::SourceTransforms(transforms) => {
current_source = current_source =
transforms.transform(*current_source).to_resolved().await?; transforms.transform(*current_source).to_resolved().await?;
......
...@@ -441,15 +441,11 @@ impl ModuleOptions { ...@@ -441,15 +441,11 @@ impl ModuleOptions {
} }
rules.extend([ rules.extend([
ModuleRule::new( ModuleRule::new_all(
RuleCondition::all(vec![
RuleCondition::ResourcePathEndsWith(".css".to_string()), RuleCondition::ResourcePathEndsWith(".css".to_string()),
// Only create a global CSS asset if not `@import`ed from CSS already. vec![ModuleRuleEffect::ModuleType(ModuleType::Css {
RuleCondition::not(RuleCondition::ReferenceType(ReferenceType::Css( ty: CssModuleAssetType::Default,
CssReferenceSubType::AtImport(None), })],
))),
]),
vec![ModuleRuleEffect::ModuleType(ModuleType::CssGlobal)],
), ),
ModuleRule::new( ModuleRule::new(
RuleCondition::all(vec![ RuleCondition::all(vec![
...@@ -463,18 +459,6 @@ impl ModuleOptions { ...@@ -463,18 +459,6 @@ impl ModuleOptions {
]), ]),
vec![ModuleRuleEffect::ModuleType(ModuleType::CssModule)], vec![ModuleRuleEffect::ModuleType(ModuleType::CssModule)],
), ),
ModuleRule::new(
RuleCondition::all(vec![
RuleCondition::ResourcePathEndsWith(".css".to_string()),
// Create a normal CSS asset if `@import`ed from CSS already.
RuleCondition::ReferenceType(ReferenceType::Css(
CssReferenceSubType::AtImport(None),
)),
]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Css {
ty: CssModuleAssetType::Default,
})],
),
ModuleRule::new( ModuleRule::new(
RuleCondition::all(vec![ RuleCondition::all(vec![
RuleCondition::ResourcePathEndsWith(".module.css".to_string()), RuleCondition::ResourcePathEndsWith(".module.css".to_string()),
...@@ -487,14 +471,21 @@ impl ModuleOptions { ...@@ -487,14 +471,21 @@ impl ModuleOptions {
ty: CssModuleAssetType::Module, ty: CssModuleAssetType::Module,
})], })],
), ),
// Ecmascript CSS Modules referencing the actual CSS module to include it
ModuleRule::new_internal( ModuleRule::new_internal(
RuleCondition::ResourcePathEndsWith(".css".to_string()), RuleCondition::ResourcePathEndsWith(".module.css".to_string()),
vec![ModuleRuleEffect::ModuleType(ModuleType::Css { vec![ModuleRuleEffect::ModuleType(ModuleType::Css {
ty: CssModuleAssetType::Default, ty: CssModuleAssetType::Module,
})], })],
), ),
ModuleRule::new_internal( // Ecmascript CSS Modules referencing the actual CSS module to list the classes
ModuleRule::new(
RuleCondition::all(vec![
RuleCondition::ReferenceType(ReferenceType::Css(
CssReferenceSubType::Analyze,
)),
RuleCondition::ResourcePathEndsWith(".module.css".to_string()), RuleCondition::ResourcePathEndsWith(".module.css".to_string()),
]),
vec![ModuleRuleEffect::ModuleType(ModuleType::Css { vec![ModuleRuleEffect::ModuleType(ModuleType::Css {
ty: CssModuleAssetType::Module, ty: CssModuleAssetType::Module,
})], })],
......
...@@ -73,6 +73,7 @@ pub enum ModuleRuleEffect { ...@@ -73,6 +73,7 @@ pub enum ModuleRuleEffect {
append: ResolvedVc<EcmascriptInputTransforms>, append: ResolvedVc<EcmascriptInputTransforms>,
}, },
SourceTransforms(ResolvedVc<SourceTransforms>), SourceTransforms(ResolvedVc<SourceTransforms>),
Ignore,
} }
#[turbo_tasks::value(serialization = "auto_for_input", shared)] #[turbo_tasks::value(serialization = "auto_for_input", shared)]
...@@ -99,7 +100,6 @@ pub enum ModuleType { ...@@ -99,7 +100,6 @@ pub enum ModuleType {
}, },
Json, Json,
Raw, Raw,
CssGlobal,
CssModule, CssModule,
Css { Css {
ty: CssModuleAssetType, ty: CssModuleAssetType,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment