forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: using rspack to bundle #1
Draft
hardfist
wants to merge
13
commits into
main
Choose a base branch
from
rspack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7dee40c
chore: add rspack dep
hardfist f243d2c
chore: use rspack_core in cli
hardfist 8f10275
chore: update dep
hardfist 6c9ad23
chore: fix compile error
hardfist c6b6897
chore: add rspack dep
hardfist 6891da8
chore: clean code
hardfist 5060d5b
chore: fix runtime missing
hardfist 2847a42
chore: fix core
hardfist 346d0c9
chore: fix compile error
hardfist 3e8fc6b
chore: fix deno_emit error
hardfist 501552b
chore: remove unnecessary files
hardfist 5e872a6
chore: improve logs
hardfist ae9a11d
chore: clear warning
hardfist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ pub mod task; | |
pub mod test; | ||
pub mod upgrade; | ||
pub mod vendor; | ||
pub mod pack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
mod rspack_bundle; | ||
use std::sync::Arc; | ||
|
||
use deno_core::error::AnyError; | ||
|
||
use deno_terminal::colors; | ||
|
||
use crate::args::BundleFlags; | ||
use crate::args::Flags; | ||
|
||
use crate::factory::CliFactory; | ||
use crate::tools::pack::rspack_bundle::rspack; | ||
pub async fn pack( | ||
flags: Arc<Flags>, | ||
bundle_flags: BundleFlags, | ||
) -> Result<(), AnyError> { | ||
log::info!( | ||
"{}", | ||
colors::yellow("⚠️ Using Rspack to Bundle"), | ||
); | ||
let factory = CliFactory::from_flags(flags); | ||
rspack(factory, &bundle_flags).await?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
use std::sync::Arc; | ||
use deno_core::error::AnyError; | ||
use rspack_core::ResolverFactory; | ||
use rspack_ids::NaturalChunkIdsPlugin; | ||
use rspack_ids::NamedModuleIdsPlugin; | ||
use rspack_core::JavascriptParserOptions; | ||
use rspack_core::ModuleType; | ||
use rspack_core::ParserOptions; | ||
use rspack_core::ParserOptionsByModuleType; | ||
use rspack_plugin_runtime::{RuntimePlugin}; | ||
use rspack_core::{ | ||
CacheOptions, ChunkLoading, ChunkLoadingType, Compiler, CompilerOptions, Context, | ||
CrossOriginLoading, DevServerOptions, EntryOptions, Environment, Experiments, Filename, | ||
HashDigest, HashFunction, HashSalt, MangleExportsOption, Mode, ModuleOptions, Optimization, | ||
OutputOptions, PathInfo, Plugin, PublicPath, Resolve, SideEffectOption, SnapshotOptions, | ||
StatsOptions, Target, UsedExportsOption, WasmLoading, | ||
}; | ||
use rspack_fs::AsyncNativeFileSystem; | ||
use rspack_plugin_entry::EntryPlugin; | ||
use rspack_plugin_javascript::JsPlugin; | ||
use rspack_plugin_schemes::DataUriPlugin; | ||
use crate::{CliFactory}; | ||
use crate::args::BundleFlags; | ||
|
||
pub async fn rspack( | ||
_factory: CliFactory, | ||
bundle_flags: &BundleFlags, | ||
) -> Result<(), AnyError> { | ||
let output_filesystem = AsyncNativeFileSystem {}; | ||
let root = std::env::current_dir().unwrap(); | ||
let context = Context::from(root.clone()); | ||
let entry_request: String = root | ||
.join(bundle_flags.source_file.clone()) | ||
.canonicalize() | ||
.unwrap() | ||
.to_string_lossy() | ||
.to_string(); | ||
let options = CompilerOptions { | ||
context: Context::from(root.clone()), | ||
dev_server: DevServerOptions::default(), | ||
output: OutputOptions { | ||
chunk_load_timeout: Default::default(), | ||
charset: Default::default(), | ||
css_head_data_compression: Default::default(), | ||
import_meta_name: Default::default(), | ||
path: root.clone(), | ||
pathinfo: PathInfo::Bool(false), | ||
clean: false, | ||
public_path: PublicPath::Auto, | ||
asset_module_filename: Filename::from(String::from("asset-[name].js")), | ||
wasm_loading: WasmLoading::Disable, | ||
webassembly_module_filename: Filename::from(String::from("webassembly.js")), | ||
unique_name: "main".into(), | ||
chunk_loading: ChunkLoading::Enable(ChunkLoadingType::Import), | ||
chunk_loading_global: String::new(), | ||
filename: Filename::from(String::from(bundle_flags.out_file.clone().unwrap_or("output.js".to_string()))), | ||
chunk_filename: Filename::from(String::from("[id].js")), | ||
cross_origin_loading: CrossOriginLoading::Disable, | ||
css_filename: Filename::from(String::from("[name].css")), | ||
css_chunk_filename: Filename::from(String::from("[id].css")), | ||
hot_update_main_filename: Filename::from(String::from("[name].[hash].hot-update.js")), | ||
hot_update_chunk_filename: Filename::from(String::from("[id].[hash].hot-update.js")), | ||
hot_update_global: String::new(), | ||
library: None, | ||
enabled_library_types: None, | ||
strict_module_error_handling: false, | ||
global_object: String::from("window"), | ||
import_function_name: String::from("import"), | ||
iife: false, | ||
module: false, | ||
trusted_types: None, | ||
source_map_filename: Filename::from(String::from("[file].map")), | ||
hash_function: HashFunction::MD4, | ||
hash_digest: HashDigest::Hex, | ||
hash_digest_length: 20, | ||
hash_salt: HashSalt::Salt(String::from("salt")), | ||
async_chunks: false, | ||
worker_chunk_loading: ChunkLoading::Disable, | ||
worker_wasm_loading: WasmLoading::Disable, | ||
worker_public_path: String::new(), | ||
script_type: String::from("text/javascript"), | ||
environment: Environment { | ||
r#const: Some(true), | ||
arrow_function: Some(true), | ||
}, | ||
}, | ||
target: Target::new(&vec!["es2022".to_string(), "node".to_string()]).unwrap(), | ||
mode: Mode::Development, | ||
resolve: Resolve { | ||
extensions: Some(vec![".js".to_string()]), | ||
..Default::default() | ||
}, | ||
resolve_loader: Resolve { | ||
extensions: Some(vec![".js".to_string()]), | ||
..Default::default() | ||
}, | ||
module: ModuleOptions { | ||
parser: Some(ParserOptionsByModuleType::from_iter([( | ||
ModuleType::JsAuto, | ||
ParserOptions::Javascript(JavascriptParserOptions { | ||
dynamic_import_fetch_priority: Default::default(), | ||
override_strict: Default::default(), | ||
import_meta: Default::default(), | ||
dynamic_import_mode: rspack_core::DynamicImportMode::Eager, | ||
dynamic_import_prefetch: rspack_core::JavascriptParserOrder::Order(1), | ||
dynamic_import_preload: rspack_core::JavascriptParserOrder::Order(1), | ||
url: rspack_core::JavascriptParserUrl::Disable, | ||
expr_context_critical: false, | ||
wrapped_context_critical: false, | ||
exports_presence: None, | ||
import_exports_presence: None, | ||
reexport_exports_presence: None, | ||
strict_export_presence: false, | ||
worker: vec![], | ||
}), | ||
)])), | ||
// generator: Some(GeneratorOptionsByModuleType::from_iter(generator.iter())), | ||
..Default::default() | ||
}, | ||
stats: StatsOptions::default(), | ||
snapshot: SnapshotOptions, | ||
cache: CacheOptions::default(), | ||
experiments: Experiments::default(), | ||
optimization: Optimization { | ||
concatenate_modules: false, | ||
remove_available_modules: false, | ||
provided_exports: false, | ||
mangle_exports: MangleExportsOption::False, | ||
inner_graph: true, | ||
used_exports: UsedExportsOption::default(), | ||
side_effects: SideEffectOption::default(), | ||
}, | ||
profile: false, | ||
bail: false, | ||
__references:Default::default(), | ||
node: None, | ||
}; | ||
let mut plugins: Vec<Box<dyn Plugin>> = Vec::new(); | ||
|
||
let plugin_options = EntryOptions { | ||
name: Some("main".to_string()), | ||
runtime: None, | ||
chunk_loading: None, | ||
async_chunks: None, | ||
public_path: None, | ||
base_uri: None, | ||
filename:None, | ||
library: None, | ||
depend_on: None, | ||
layer: Default::default(), | ||
}; | ||
|
||
let entry_plugin = Box::new(EntryPlugin::new(context, entry_request, plugin_options)); | ||
plugins.push(Box::<JsPlugin>::default()); | ||
plugins.push(entry_plugin); | ||
plugins.push(Box::<NaturalChunkIdsPlugin>::default()); | ||
plugins.push(Box::<NamedModuleIdsPlugin>::default()); | ||
plugins.push(Box::<DataUriPlugin>::default()); | ||
plugins.push(Box::<RuntimePlugin>::default()); | ||
let resolver_factory = Arc::new(ResolverFactory::new(options.resolve.clone())); | ||
let loader_resolver_factory = Arc::new(ResolverFactory::new(options.resolve_loader.clone())); | ||
let mut compiler = Compiler::new(options, plugins, output_filesystem, resolver_factory, loader_resolver_factory); | ||
compiler.build().await.expect("build failed"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[toolchain] | ||
channel = "1.80.0" | ||
channel = "nightly-2024-06-07" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rspack use nightly version of rust,but can switch to stable version in the future |
||
components = ["rustfmt", "clippy"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const answer = 42; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { answer } from "./answer.mjs"; | ||
console.log(answer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rspack only support multi thread mode now, but can support single thread in the future