Skip to content

Commit

Permalink
feat: mini-css-extract-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Dec 23, 2023
1 parent 74a76e7 commit 7232ebd
Show file tree
Hide file tree
Showing 28 changed files with 1,440 additions and 32 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ export const enum BuiltinPluginName {
CopyRspackPlugin = 'CopyRspackPlugin',
HtmlRspackPlugin = 'HtmlRspackPlugin',
SwcJsMinimizerRspackPlugin = 'SwcJsMinimizerRspackPlugin',
SwcCssMinimizerRspackPlugin = 'SwcCssMinimizerRspackPlugin'
SwcCssMinimizerRspackPlugin = 'SwcCssMinimizerRspackPlugin',
CssExtractPlugin = 'CssExtractPlugin'
}

export function cleanupGlobalTrace(): void
Expand Down Expand Up @@ -713,6 +714,16 @@ export interface RawCrossOriginLoading {
boolPayload?: boolean
}

export interface RawCssExtractPluginOption {
filename: string
chunkFilename: string
ignoreOrder: boolean
insert?: string
attributes: Record<string, string>
linkType?: string
runtime: boolean
}

export interface RawCssModulesConfig {
localsConvention: "asIs" | "camelCase" | "camelCaseOnly" | "dashes" | "dashesOnly"
localIdentName: string
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rspack_plugin_devtool = { path = "../rspack_plugin_devtool" }
rspack_plugin_ensure_chunk_conditions = { path = "../rspack_plugin_ensure_chunk_conditions" }
rspack_plugin_entry = { path = "../rspack_plugin_entry" }
rspack_plugin_externals = { path = "../rspack_plugin_externals" }
rspack_plugin_extract_css = { path = "../rspack_plugin_extract_css" }
rspack_plugin_hmr = { path = "../rspack_plugin_hmr" }
rspack_plugin_html = { path = "../rspack_plugin_html" }
rspack_plugin_javascript = { path = "../rspack_plugin_javascript" }
Expand Down
16 changes: 13 additions & 3 deletions crates/rspack_binding_options/src/options/raw_builtins/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod raw_banner;
mod raw_copy;
mod raw_css_extract;
mod raw_html;
mod raw_limit_chunk_count;
mod raw_mf;
Expand Down Expand Up @@ -41,15 +42,16 @@ use rspack_plugin_wasm::enable_wasm_loading_plugin;
use rspack_plugin_web_worker_template::web_worker_template_plugin;
use rspack_plugin_worker::WorkerPlugin;

use self::raw_mf::{
RawConsumeSharedPluginOptions, RawContainerReferencePluginOptions, RawProvideOptions,
};
pub use self::{
raw_banner::RawBannerPluginOptions, raw_copy::RawCopyRspackPluginOptions,
raw_html::RawHtmlRspackPluginOptions, raw_limit_chunk_count::RawLimitChunkCountPluginOptions,
raw_mf::RawContainerPluginOptions, raw_progress::RawProgressPluginOptions,
raw_swc_js_minimizer::RawSwcJsMinimizerRspackPluginOptions,
};
use self::{
raw_css_extract::RawCssExtractPluginOption,
raw_mf::{RawConsumeSharedPluginOptions, RawContainerReferencePluginOptions, RawProvideOptions},
};
use crate::{
RawEntryPluginOptions, RawExternalItemWrapper, RawExternalsPluginOptions,
RawHttpExternalsRspackPluginOptions, RawOptionsApply, RawSplitChunksOptions,
Expand Down Expand Up @@ -93,6 +95,7 @@ pub enum BuiltinPluginName {
HtmlRspackPlugin,
SwcJsMinimizerRspackPlugin,
SwcCssMinimizerRspackPlugin,
CssExtractPlugin,
}

#[napi(object)]
Expand Down Expand Up @@ -271,6 +274,13 @@ impl RawOptionsApply for BuiltinPlugin {
.boxed();
plugins.push(plugin);
}
BuiltinPluginName::CssExtractPlugin => {
let plugin = rspack_plugin_extract_css::plugin::PluginCssExtract::new(
downcast_into::<RawCssExtractPluginOption>(self.options)?.into(),
)
.boxed();
plugins.push(plugin);
}
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::collections::HashMap;

use napi_derive::napi;
use rspack_plugin_extract_css::plugin::CssExtractOptions;

#[napi(object)]
pub struct RawCssExtractPluginOption {
pub filename: String,
pub chunk_filename: String,
pub ignore_order: bool,
pub insert: Option<String>,
pub attributes: HashMap<String, String>,
pub link_type: Option<String>,
pub runtime: bool,
}

impl From<RawCssExtractPluginOption> for CssExtractOptions {
fn from(value: RawCssExtractPluginOption) -> Self {
Self {
filename: value.filename,
chunk_filename: value.chunk_filename,
ignore_order: value.ignore_order,
insert: value.insert,
attributes: value.attributes.into_iter().collect(),
link_type: value.link_type,
runtime: value.runtime,
}
}
}
3 changes: 1 addition & 2 deletions crates/rspack_core/src/plugin/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ pub type BoxedParserAndGeneratorBuilder =

#[derive(Default)]
pub struct ApplyContext {
pub(crate) registered_parser_and_generator_builder:
DashMap<ModuleType, BoxedParserAndGeneratorBuilder>,
pub registered_parser_and_generator_builder: DashMap<ModuleType, BoxedParserAndGeneratorBuilder>,
}

impl ApplyContext {
Expand Down
42 changes: 42 additions & 0 deletions crates/rspack_plugin_extract_css/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
edition = "2021"
license = "MIT"
name = "rspack_plugin_extract_css"
repository = "https://github.com/web-infra-dev/rspack"
version = "0.1.0"

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
bitflags = { workspace = true }
heck = "0.4.1"
indexmap = { workspace = true }
once_cell = { workspace = true }
rayon = { workspace = true }
regex = { workspace = true }
rkyv = { workspace = true, features = ["indexmap", "validation"] }
rspack_core = { path = "../rspack_core" }
rspack_error = { path = "../rspack_error" }
rspack_hash = { path = "../rspack_hash" }
rspack_identifier = { path = "../rspack_identifier" }
rspack_plugin_runtime = { path = "../rspack_plugin_runtime" }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sugar_path = { workspace = true }
swc_core = { workspace = true, features = [
"css_ast",
"css_codegen",
"css_parser",
"css_utils",
"css_visit",
"css_visit_path",
"css_compat",
"css_modules",
"css_prefixer",
"css_minifier",
] }
tokio = { workspace = true }
tracing = { workspace = true }
urlencoding = "2.1.2"
ustr = { workspace = true }
22 changes: 22 additions & 0 deletions crates/rspack_plugin_extract_css/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022-present Bytedance, Inc. and its affiliates.


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 7232ebd

Please sign in to comment.