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

Disabling file concatenation #3882

Closed
dmail opened this issue Nov 25, 2020 · 13 comments · Fixed by #4549
Closed

Disabling file concatenation #3882

dmail opened this issue Nov 25, 2020 · 13 comments · Fixed by #4549

Comments

@dmail
Copy link
Contributor

dmail commented Nov 25, 2020

Context

For some projects I would like to use rollup to benefit from tree-shaking and url hashing without generating chunks (disable concatenation of files). From my understanding preserveModules is the option to use for that situation. According to my tests preserveModules behaviour is not what I expected.

The following code illustrates what I have in mind.

import { rollup } from "rollup"
import { fileURLToPath } from "url"

const start = async () => {
  const projectDirectoryUrl = new URL("./", import.meta.url)

  const fileContents = {
    "./main.js": `import { value } from "./dep.js"
console.log(value)`,
    "./dep.js": `export const value = 42`,
  }

  const rollupBundle = await rollup({
    input: ["./main.js"],
    plugins: [
      {
        resolveId: (id) => {
          return id
        },
        load: (id) => {
          return fileContents[id]
        },
      },
    ],
  })

  await rollupBundle.write({
    dir: fileURLToPath(`${projectDirectoryUrl}dist`),
    preserveModules: true,
    chunkFileNames: `[name]-[hash].js`,
  })
}

start()

Expected Behavior / Situation

Rollup write files with hash in their names such as

dist/main-25e95a00.js
dist/dep-5dd85f23.js

Actual Behavior / Situation

Rollup write files without hash under _virtual directory.

dist/_virtual/main.js
dist/_virtual/dep.js

Modification Proposal

Allow to disable chunks using preserveModules options or something else and update import paths to get hash in urls.

@lukastaegert
Copy link
Member

This has been discussed in the past in different contexts, see e.g. #3684. The way forward will be to fully respect the entryFileNames and chunkFileNames options when preserving modules. Unfortunately due to some choices in the current implementation, this will be a breaking change and is therefore marked for an upcoming 3.0 release. No due date for that, unfortunately.

@dmail
Copy link
Contributor Author

dmail commented Nov 26, 2020

Thank you for the feedback 👍. I have no special urgency around this need, it's more for experimentation.
I saw the issue about node_modules but could not follow what was the root issue in that thread, sorry if that's a duplicate.

@lukastaegert
Copy link
Member

It is now kind of tracked here: https://github.com/rollup/rollup/projects/3

@dmail
Copy link
Contributor Author

dmail commented Sep 13, 2021

By the way I found a way to disable concatenation by accident.

In short, inside the "load" hook, I emit a chunk for every js file.

async load(id) {
  if (id.endsWith('.js')) {
    this.emit({type: "chunk", id })
  }
}

.

@tirrth
Copy link

tirrth commented Jun 30, 2022

@dmail Your fix doesn't seem to be working for me. Does anyone's got some sorta workaround for this?

@lukastaegert
Copy link
Member

Resolved in #4565

@lukastaegert
Copy link
Member

This issue has been resolved via #4565 as part of rollup@3.0.0-3. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-3 or npm install rollup@beta. It will likely become part of a regular release later.

@lukastaegert
Copy link
Member

This issue has been resolved via #4565 as part of rollup@3.0.0-4. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-4 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4565 as part of rollup@3.0.0-5. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-5 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4565 as part of rollup@3.0.0-6. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-6 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4565 as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-7 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4565 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via npm install rollup@3.0.0-8 or npm install rollup@beta. It will likely become part of a regular release later.

@rollup-bot
Copy link
Collaborator

This issue has been resolved via #4565 as part of rollup@3.0.0. You can test it via npm install rollup.

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

Successfully merging a pull request may close this issue.

4 participants