Skip to content
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

Rolldown doesn't support output.file option #624

Open
kazupon opened this issue Mar 21, 2024 · 3 comments
Open

Rolldown doesn't support output.file option #624

kazupon opened this issue Mar 21, 2024 · 3 comments

Comments

@kazupon
Copy link
Sponsor Contributor

kazupon commented Mar 21, 2024

reproduction repo

https://github.com/kazupon/rolldown-output-repro1

background

I noticed on #610

reproduction step

npm install

npm run build

tree -L 2
.
├── README.md
├── app.js
├── dist
│   ├── app.js
│   └── app.js.map
├── node_modules
│   ├── @rolldown
│   ├── @rollup
│   ├── @types
│   ├── fsevents
│   └── rollup
├── package-lock.json
├── package.json
├── rolldown.js
├── rollup.js
└── rollup_build
    ├── rollup.js
    └── rollup.js.map

9 directories, 10 files

rolldown write output option:

import { rolldown } from '@rolldown/node'

const bundle = await rolldown({
  input: 'app.js',
})

await bundle.write({
  format: 'esm',
  sourcemap: true,
  file: 'rolldown_build/rolldown.js'
})

rolldown cannot output to 'rolldown_build/rolldown.js' with file option.

rollup can ouput with file option.

rolldown write should have the same result as rollup.

@kazupon
Copy link
Sponsor Contributor Author

kazupon commented Mar 21, 2024

Ah, I see, the Rust side write does not receive output otpions from the JS side, it writes with the outputoptions passed to the Bundler when it initializes.

impl Bundler {
#[napi(constructor)]
pub fn new(
env: Env,
input_options: BindingInputOptions,
output_options: BindingOutputOptions,
) -> napi::Result<Self> {
try_init_custom_trace_subscriber(env);
let ret = normalize_binding_options(input_options, output_options)?;
Ok(Self {
inner: Mutex::new(NativeBundler::with_plugins(
ret.input_options,
ret.output_options,
ret.plugins,
)),
})
}
#[napi]
pub async fn write(&self) -> napi::Result<BindingOutputs> {
self.write_impl().await
}

If we pass output options to write, then we have to test the performance ((de)serialize).

@hyf0
Copy link
Member

hyf0 commented Mar 21, 2024

@kazupon

the Rust side write does not receive output otpions from the JS side

Nope. It does take the output options from js side, which is the options that passed from write or generate. I'm not sure the problem. But it probably due to we haven't support output.file option.

You should be able to use output.entryFileName: 'rolldown_build/rolldown.js' to do this. Or output.dir: 'rolldown_build' with output.entryFileName: 'rolldown.js'.

Notice that this only works out in single entry.

You see the functionality of output.file could be done with other options. I personally feel it's kind of overengineering. Let me talk with team about how we handle these kind of options.

@hyf0 hyf0 changed the title rolldown write should have the same result as rollup. Rolldown doesn't support output.file option Mar 21, 2024
@sapphi-red
Copy link
Contributor

FWIW Vite does not support output.file as we generate multiple files. vitejs/vite#11096 (comment), vitejs/vite#14909

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants