Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ice-lab/icepack
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed Jan 3, 2024
2 parents bd58a15 + b0a780c commit 116142f
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .github/actions/clone-crates/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:
required: false
type: string
ref:
default: 'v0.4.3'
default: 'v0.4.5'
required: false
type: string
temp:
Expand Down
28 changes: 28 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ tikv-jemallocator = { version = "=0.5.4", features = ["disable_initial_exec_tl
codegen-units = 16 # debug build will cause runtime panic if codegen-unints is default
debug = 2
incremental = true
panic = "abort"

[profile.release]
codegen-units = 1
debug = false
lto = false # disabled by now, because it will significantly increase our compile time.
lto = false # disabled by now, because it will significantly increase our compile time.
opt-level = 3
panic = "abort"
strip = true
124 changes: 25 additions & 99 deletions crates/binding_options/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use napi_derive::napi;
use rspack_core::{
BoxPlugin, CompilerOptions, Context, DevServerOptions, Devtool, Experiments, IncrementalRebuild,
IncrementalRebuildMakeState, MangleExportsOption, ModuleOptions, ModuleType, OutputOptions,
PluginExt, TreeShaking, Optimization,
};
use rspack_plugin_javascript::{
FlagDependencyExportsPlugin, FlagDependencyUsagePlugin, MangleExportsPlugin,
SideEffectsFlagPlugin,
CompilerOptions, Context, DevServerOptions, Devtool, Experiments, IncrementalRebuild,
IncrementalRebuildMakeState, ModuleOptions, Target, OutputOptions, TreeShaking, Optimization,
};

use serde::Deserialize;

use rspack_binding_options::{
RawBuiltins, RawCacheOptions, RawContext, RawDevServer, RawDevtool, RawExperiments,
RawMode, RawNodeOption, RawOutputOptions, RawResolveOptions, RawOptionsApply,
RawSnapshotOptions, RawStatsOptions, RawTarget, RawModuleOptions,
RawBuiltins, RawCacheOptions, RawDevServer, RawExperiments,
RawMode, RawNodeOption, RawOutputOptions, RawResolveOptions,
RawSnapshotOptions, RawStatsOptions, RawModuleOptions,
};

mod raw_module;
Expand All @@ -32,16 +28,13 @@ pub use raw_optimization::*;
pub struct RSPackRawOptions {
#[napi(ts_type = "undefined | 'production' | 'development' | 'none'")]
pub mode: Option<RawMode>,
#[napi(ts_type = "Array<string>")]
pub target: RawTarget,
#[napi(ts_type = "string")]
pub context: RawContext,
pub target: Vec<String>,
pub context: String,
pub output: RawOutputOptions,
pub resolve: RawResolveOptions,
pub resolve_loader: RawResolveOptions,
pub module: RawModuleOptions,
#[napi(ts_type = "string")]
pub devtool: RawDevtool,
pub devtool: String,
pub optimization: RspackRawOptimizationOptions,
pub stats: RawStatsOptions,
pub dev_server: RawDevServer,
Expand All @@ -50,25 +43,26 @@ pub struct RSPackRawOptions {
pub experiments: RawExperiments,
pub node: Option<RawNodeOption>,
pub profile: bool,
pub bail: bool,
pub builtins: RawBuiltins,
pub features: RawFeatures,
}

impl RawOptionsApply for RSPackRawOptions {
type Options = CompilerOptions;

fn apply(self, plugins: &mut Vec<BoxPlugin>) -> Result<Self::Options, rspack_error::Error> {
impl RSPackRawOptions {
pub fn apply(
self,
plugins: &mut Vec<rspack_core::BoxPlugin>,
) -> rspack_error::Result<CompilerOptions> {
let context: Context = self.context.into();
let output: OutputOptions = self.output.apply(plugins)?;
let output: OutputOptions = self.output.try_into()?;
let resolve = self.resolve.try_into()?;
let resolve_loader = self.resolve_loader.try_into()?;
let devtool: Devtool = self.devtool.into();
let mode = self.mode.unwrap_or_default().into();
let module: ModuleOptions = self.module.apply(plugins)?;
let target = self.target.apply(plugins)?;
let module: ModuleOptions = self.module.try_into()?;
let target = Target::new(&self.target)?;
let cache = self.cache.into();
let experiments = Experiments {
lazy_compilation: self.experiments.lazy_compilation,
incremental_rebuild: IncrementalRebuild {
make: self
.experiments
Expand All @@ -77,7 +71,6 @@ impl RawOptionsApply for RSPackRawOptions {
.then(IncrementalRebuildMakeState::default),
emit_asset: self.experiments.incremental_rebuild.emit_asset,
},
async_web_assembly: self.experiments.async_web_assembly,
new_split_chunks: self.experiments.new_split_chunks,
top_level_await: self.experiments.top_level_await,
rspack_future: self.experiments.rspack_future.into(),
Expand All @@ -90,92 +83,24 @@ impl RawOptionsApply for RSPackRawOptions {
);
optimization = split_chunk_strategy.apply(plugins, context.to_string())?;
} else {
optimization = IS_ENABLE_NEW_SPLIT_CHUNKS.set(&experiments.new_split_chunks, || {
self.optimization.apply(plugins)
})?;
optimization = IS_ENABLE_NEW_SPLIT_CHUNKS
.set(&experiments.new_split_chunks, || {
self.optimization.try_into()
})?;
}

let stats = self.stats.into();
let snapshot = self.snapshot.into();
let node = self.node.map(|n| n.into());
let dev_server: DevServerOptions = self.dev_server.into();

plugins.push(rspack_plugin_schemes::DataUriPlugin.boxed());
plugins.push(rspack_plugin_schemes::FileUriPlugin.boxed());

plugins.push(
rspack_plugin_asset::AssetPlugin::new(rspack_plugin_asset::AssetConfig {
parse_options: module
.parser
.as_ref()
.and_then(|x| x.get(&ModuleType::Asset))
.and_then(|x| x.get_asset(&ModuleType::Asset).cloned()),
})
.boxed(),
);
plugins.push(rspack_plugin_json::JsonPlugin {}.boxed());
plugins.push(rspack_plugin_runtime::RuntimePlugin {}.boxed());
if experiments.lazy_compilation {
plugins.push(rspack_plugin_runtime::LazyCompilationPlugin {}.boxed());
}
if experiments.async_web_assembly {
plugins.push(rspack_plugin_wasm::AsyncWasmPlugin::new().boxed());
}
plugins.push(rspack_plugin_javascript::JsPlugin::new().boxed());
plugins.push(rspack_plugin_javascript::InferAsyncModulesPlugin {}.boxed());

if devtool.source_map() {
plugins.push(
rspack_plugin_devtool::DevtoolPlugin::new(rspack_plugin_devtool::DevtoolPluginOptions {
inline: devtool.inline(),
append: !devtool.hidden(),
namespace: output.unique_name.clone(),
columns: !devtool.cheap(),
no_sources: devtool.no_sources(),
public_path: None,
})
.boxed(),
);
}

if experiments.rspack_future.new_treeshaking {
if optimization.side_effects.is_enable() {
plugins.push(SideEffectsFlagPlugin::default().boxed());
}
if optimization.provided_exports {
plugins.push(FlagDependencyExportsPlugin::default().boxed());
}
if optimization.used_exports.is_enable() {
plugins.push(FlagDependencyUsagePlugin::default().boxed());
}
}
if optimization.mangle_exports.is_enable() {
// We already know mangle_exports != false
plugins.push(
MangleExportsPlugin::new(!matches!(
optimization.mangle_exports,
MangleExportsOption::Size
))
.boxed(),
);
}

// Notice the plugin need to be placed after SplitChunksPlugin
if optimization.remove_empty_chunks {
plugins.push(rspack_plugin_remove_empty_chunks::RemoveEmptyChunksPlugin.boxed());
}

plugins.push(rspack_plugin_ensure_chunk_conditions::EnsureChunkConditionsPlugin.boxed());

plugins.push(rspack_plugin_warn_sensitive_module::WarnCaseSensitiveModulesPlugin.boxed());
// Add custom plugins.
plugins.push(plugin_manifest::ManifestPlugin::new().boxed());
plugins.push(Box::new(plugin_manifest::ManifestPlugin::new()));
let mut builtins = self.builtins.apply(plugins)?;
if experiments.rspack_future.new_treeshaking {
builtins.tree_shaking = TreeShaking::False;
}

Ok(Self::Options {
Ok(CompilerOptions {
context,
mode,
module,
Expand All @@ -192,6 +117,7 @@ impl RawOptionsApply for RSPackRawOptions {
node,
dev_server,
profile: self.profile,
bail: self.bail,
builtins,
})
}
Expand Down
Loading

0 comments on commit 116142f

Please sign in to comment.