Skip to content

feat(minify): add directives option#15690

Closed
suxin2017 wants to merge 1 commit intooxc-project:mainfrom
suxin2017:feat_add_directives_config
Closed

feat(minify): add directives option#15690
suxin2017 wants to merge 1 commit intooxc-project:mainfrom
suxin2017:feat_add_directives_config

Conversation

@suxin2017
Copy link

@suxin2017 suxin2017 commented Nov 14, 2025

https://terser.org/docs/options/

  • directives (default: true) -- remove redundant or non-standard directives

When the js module is of the Module type, it may output from ejs to cjs. Therefore, we add this configuration to keep it similar to terser

It is possible to fix the related issues

rolldown/rolldown#6880
rolldown/rolldown#6879

@suxin2017 suxin2017 marked this pull request as draft November 14, 2025 06:38
@github-actions github-actions bot added A-minifier Area - Minifier C-enhancement Category - New feature or request labels Nov 14, 2025
@suxin2017 suxin2017 marked this pull request as ready for review November 14, 2025 06:41
@sapphi-red
Copy link
Member

When the js module is of the Module type, it may output from ejs to cjs. Therefore, we add this configuration to keep it similar to terser

I don't think so. If the code is not ESM, then the code should be parsed with Script mode, which makes node.source_type.is_module() to return false.

@suxin2017
Copy link
Author

suxin2017 commented Nov 14, 2025

You're right. There is also a problem with detecting module type here

https://repl.rolldown.rs/#eNptjkEKwzAMBL8idPEl+AEu/YkvwbFLiisFW24DwX+v0tDSQy5adiVmtWFCt+FMU1xtuNfdELq/YMCg3mOrEaqUOYjHiydPcV24SLWJGa5gVIwnPY/opLTYByyc88QvsoEpzTcrP/zJ5ug5oDDFNLYssPniCYCbLE3c1wIkLo9RA6MfmiPsu3wGdu1+KiyPEqtgfwNltE1r

output

{ span: Span { start: 0, end: 35 }, source_text: ""use strict";\n\nexports.foo = 'foo'\n", comments: Vec([]), hashbang: None, directives: Vec([Directive { span: Span { start: 0, end: 13 }, expression: StringLiteral { span: Span { start: 0, end: 12 }, value: "use strict", raw: Some(""use strict""), lone_surrogates: false }, directive: "use strict" }]), body: Vec([ExpressionStatement(ExpressionStatement { span: Span { start: 15, end: 34 }, expression: AssignmentExpression(AssignmentExpression { span: Span { start: 15, end: 34 }, left: StaticMemberExpression(StaticMemberExpression { span: Span { start: 15, end: 26 }, object: Identifier(IdentifierReference { span: Span { start: 15, end: 22 }, name: "exports", reference_id: Cell { value: Some(ReferenceId(0)) } }), property: IdentifierName { span: Span { start: 23, end: 26 }, name: "foo" }, optional: false }), right: StringLiteral(StringLiteral { span: Span { start: 29, end: 34 }, value: "foo", raw: Some("'foo'"), lone_surrogates: false }), operator: Assign }) })]), scope_id: Cell { value: Some(ScopeId(0)) }, source_type: SourceType { language: JavaScript, module_kind: Module, variant: Standard } }

source_type module_kind = Module

@suxin2017
Copy link
Author

At present, it seems that adding this configuration is still quite necessary

@Boshen
Copy link
Member

Boshen commented Nov 14, 2025

At present, it seems that adding this configuration is still quite necessary

can you elaborate your use case? I try to avoid adding options until it's necessary for a specific modern usecase.

@Boshen Boshen marked this pull request as draft November 15, 2025 03:41
@sapphi-red
Copy link
Member

I think #15691 solved the same problem without a new option.

@suxin2017 suxin2017 closed this Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants