Skip to content

Commit

Permalink
fix: move minify field
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Aug 19, 2024
1 parent ff47c11 commit b4abc23
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ export interface RawSwcJsMinimizerOptions {
mangle: any
format: any
module?: boolean
minify?: boolean
}

export interface RawSwcJsMinimizerRspackPluginOptions {
Expand All @@ -1728,7 +1729,6 @@ export interface RawSwcJsMinimizerRspackPluginOptions {
exclude?: string | RegExp | (string | RegExp)[]
extractComments?: RawExtractComments
minimizerOptions: RawSwcJsMinimizerOptions
minify?: boolean
}

export interface RawToOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct RawSwcJsMinimizerRspackPluginOptions {
pub exclude: Option<RawAssetConditions>,
pub extract_comments: Option<RawExtractComments>,
pub minimizer_options: RawSwcJsMinimizerOptions,
pub minify: Option<bool>,
}

#[derive(Debug)]
Expand All @@ -36,6 +35,7 @@ pub struct RawSwcJsMinimizerOptions {
pub mangle: serde_json::Value,
pub format: serde_json::Value,
pub module: Option<bool>,
pub minify: Option<bool>,
}

fn try_deserialize_into<T>(value: serde_json::Value) -> Result<T>
Expand Down Expand Up @@ -82,12 +82,12 @@ impl TryFrom<RawSwcJsMinimizerRspackPluginOptions> for PluginOptions {
test: value.test.map(into_asset_conditions),
include: value.include.map(into_asset_conditions),
exclude: value.exclude.map(into_asset_conditions),
minify: value.minify,
minimizer_options: MinimizerOptions {
compress,
mangle,
format: try_deserialize_into(value.minimizer_options.format)?,
module: value.minimizer_options.module,
minify: value.minimizer_options.minify,
..Default::default()
},
})
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_swc_js_minimizer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ static JAVASCRIPT_ASSET_REGEXP: LazyLock<Regex> =

#[derive(Debug, Hash)]
pub struct PluginOptions {
pub minify: Option<bool>,
pub test: Option<AssetConditions>,
pub include: Option<AssetConditions>,
pub exclude: Option<AssetConditions>,
Expand All @@ -46,6 +45,7 @@ pub struct PluginOptions {

#[derive(Debug, Default)]
pub struct MinimizerOptions {
pub minify: Option<bool>,
pub compress: BoolOrDataConfig<TerserCompressorOptions>,
pub mangle: BoolOrDataConfig<MangleOptions>,
pub format: JsMinifyFormatOptions,
Expand Down Expand Up @@ -200,7 +200,7 @@ async fn process_assets(&self, compilation: &mut Compilation) -> Result<()> {
};

let js_minify_options = JsMinifyOptions {
minify: options.minify.unwrap_or(true),
minify: minimizer_options.minify.unwrap_or(true),
compress: minimizer_options.compress.clone(),
mangle: minimizer_options.mangle.clone(),
format: minimizer_options.format.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Object {
"main.js",
],
"filteredModules": undefined,
"hash": "c0151c6dfca2168c65d7",
"hash": "333e59d94047c9b4ec6c",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -176,7 +176,7 @@ Object {
"errorsCount": 0,
"filteredAssets": undefined,
"filteredModules": undefined,
"hash": "d46aa17c3e1115ff8d8a",
"hash": "a156b269cd7b4340da9d",
"modules": Array [
Object {
"assets": Array [],
Expand Down Expand Up @@ -324,7 +324,7 @@ Object {
"main.js",
],
"filteredModules": undefined,
"hash": "e9a1c09dae741d8eab71",
"hash": "a2024ddd80c1dac51782",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -691,7 +691,7 @@ Object {
"errorsCount": 0,
"filteredAssets": undefined,
"filteredModules": undefined,
"hash": "1234d41312362d1e5f6e",
"hash": "959ba20161293349edf3",
"modules": Array [
Object {
"assets": Array [],
Expand Down Expand Up @@ -1458,7 +1458,7 @@ Object {
"files": Array [
"main.js",
],
"hash": "c0151c6dfca2168c65d7",
"hash": "333e59d94047c9b4ec6c",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -1714,7 +1714,7 @@ Object {
"main.js",
],
"filteredModules": undefined,
"hash": "b05777d51d49dfde7aa8",
"hash": "add6ca394a084131cdb7",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down Expand Up @@ -2063,7 +2063,7 @@ exports.c = require(\\"./c?c=3\\");
"errorsCount": 0,
"filteredAssets": undefined,
"filteredModules": undefined,
"hash": "b1ef105808f10ca0733b",
"hash": "0e205cc26142ad8eade1",
"modules": Array [
Object {
"assets": Array [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = {
},
plugins: [
new rspack.SwcJsMinimizerRspackPlugin({
minify: false,
minimizerOptions: {
minify: false,
mangle: false
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-test-tools/tests/statsAPICases/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
entry ./fixtures/a
cjs self exports reference self [585] ./fixtures/a.js
Rspack compiled successfully (d46aa17c3e1115ff8d8a)"
Rspack compiled successfully (a156b269cd7b4340da9d)"
`);
}
};
4 changes: 2 additions & 2 deletions packages/rspack-test-tools/tests/statsAPICases/chunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
"chunkB.js",
],
"filteredModules": undefined,
"hash": "94e5f4b9ba950ceab14f",
"hash": "9aa837bfaefd1fd4ec18",
"id": "250",
"idHints": Array [],
"initial": false,
Expand Down Expand Up @@ -144,7 +144,7 @@ module.exports = {
"main.js",
],
"filteredModules": undefined,
"hash": "5e75c3a7bac911893513",
"hash": "0e471e878e0dbdf0ba5a",
"id": "909",
"idHints": Array [],
"initial": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/rspack/src/builtin-plugin/SwcJsMinimizerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export type SwcJsMinimizerRspackPluginOptions = {
exclude?: AssetConditions;
include?: AssetConditions;
extractComments?: ExtractCommentsOptions | undefined;
minify?: boolean;
minimizerOptions?: {
minify?: boolean;
compress?: TerserCompressOptions | boolean;
mangle?: TerserMangleOptions | boolean;
format?: JsFormatOptions & ToSnakeCaseProperties<JsFormatOptions>;
Expand Down Expand Up @@ -289,7 +289,6 @@ export const SwcJsMinimizerRspackPlugin = create(
}

return {
minify: options?.minify,
test: options?.test,
include: options?.include,
exclude: options?.exclude,
Expand All @@ -298,6 +297,7 @@ export const SwcJsMinimizerRspackPlugin = create(
compress,
mangle,
format,
minify: options?.minimizerOptions?.minify,
module: options?.minimizerOptions?.module
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = {
exclude?: AssetConditions;
include?: AssetConditions;
extractComments?: boolean | RegExp;
minify?: boolean;
minimizerOptions: {
minimizerOptions?: {
minify?: boolean;
compress?: TerserCompressOptions | boolean;
mangle?: TerserMangleOptions | boolean;
module?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = {
exclude?: AssetConditions;
include?: AssetConditions;
extractComments?: boolean | RegExp;
minify?: boolean;
minimizerOptions?: {
minify?: boolean;
compress?: TerserCompressOptions | boolean;
mangle?: TerserMangleOptions | boolean;
module?: boolean;
Expand Down

0 comments on commit b4abc23

Please sign in to comment.