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

"Pre-bundling dependencies" in node_modules chunking does not respect plugins queue #5364

Closed
7 tasks done
lifeart opened this issue Oct 20, 2021 · 8 comments
Closed
7 tasks done

Comments

@lifeart
Copy link

lifeart commented Oct 20, 2021

Describe the bug

Why?
Some libraries have DEBUG flag in codebase to ship more debugging information into development build,
but "Pre-bundling dependencies" does not respect plugins, responsible for this transformation, and it fails it.

I'm trying to configure debug globals in glimmex application, using vite plugin:

https://github.com/lifeart/vite-plugin-glimmerx

it has ordering: enforce: "pre", and babel transformation itself works just fine, but (checked output), but, I don't see it applied to codebase (compiled node_modules dependency) once I have server running.

I'm trying to replace source code manually, and it's also don't work (in "transform" plugin stage)

and I see generated chunk, not processed by plugin in .vite directory:

import {
  __esm
} from "./chunk-XNAE4CLY.js";

// node_modules/@glimmer/env/dist/modules/es2017/index.js
var DEBUG;
var init_es2017 = __esm({
  "node_modules/@glimmer/env/dist/modules/es2017/index.js"() {
    DEBUG = false;
  }
});

export {
  DEBUG,
  init_es2017
};
//# sourceMappingURL=chunk-HBQKIAIV.js.map

looks like this "chinking" logic, likely located here: https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/importAnalysisBuild.ts does not respect plugins queue...

related issue: glimmerjs/glimmer-vm#1350

Reproduction

https://github.com/lifeart/_vite_precompile_error_reproduction

System Info

System:
    OS: macOS 11.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 855.07 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.11.0 - ~/.volta/tools/image/node/16.11.0/bin/node
    Yarn: 1.22.10 - ~/.volta/tools/image/yarn/1.22.10/bin/yarn
    npm: 8.0.0 - ~/.volta/tools/image/node/16.11.0/bin/npm
    Watchman: 2021.08.02.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 94.0.4606.81
    Safari: 15.0
  npmPackages:
    vite: ^2.6.4 => 2.6.5

Used Package Manager

yarn

Logs

No response

Validations

@lifeart
Copy link
Author

lifeart commented Oct 20, 2021

tldr: 'Pre-bundling dependencies' step should respect plugin transforms, or have a way to delay or skip some of them

@lifeart lifeart changed the title node_modules chunking does not respect plugins queue "Pre-bundling dependencies" in node_modules chunking does not respect plugins queue Oct 20, 2021
@bluwy
Copy link
Member

bluwy commented Oct 20, 2021

Vite's current architecture doesn't involve plugin transforms in the prebundling process, there are discussions around this though. At the meantime, you can use optimizeDeps.esbuildOptions.define or a esbuild plugin via optimizeDeps.esbuildOptions.plugins if needed.

@lifeart
Copy link
Author

lifeart commented Oct 20, 2021

@bluwy optimizeDeps.esbuildOptions.define won't work for my case, because debug is imported (not global)

import { DEBUG } from '@glimmer/env'

lifeart added a commit to lifeart/glimmerx-workshop that referenced this issue Oct 20, 2021
@bluwy
Copy link
Member

bluwy commented Oct 20, 2021

You can make a custom esbuild plugin then that resolves @glimmer/env to a file with export const DEBUG = true. Hooking into build.onLoad should work.

@NullVoxPopuli
Copy link

How would you replace all occurrences of DEBUG with a boolean? Is that possible? That's what babel-plugin-debug-macros does 🤔

@bluwy
Copy link
Member

bluwy commented Mar 28, 2022

Closing as #5364 (comment) should do the trick.

How would you replace all occurrences of DEBUG with a boolean? Is that possible? That's what babel-plugin-debug-macros does 🤔

You can use the define option, e.g. define: { DEBUG: false }

@bluwy bluwy closed this as completed Mar 28, 2022
@lifeart
Copy link
Author

lifeart commented Mar 28, 2022

@bluwy it’s not global constant! Its variable

@bluwy
Copy link
Member

bluwy commented Mar 28, 2022

I don't understand what do you mean, can you explain how the esbuild plugin isn't working for you? The contents of @glimmer/env is rather simple to be replaced.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants