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

@rollup/plugin-replace issue with include/exclude options in windows #1522

Closed
patak-dev opened this issue Jan 13, 2021 · 3 comments · Fixed by #1693
Closed

@rollup/plugin-replace issue with include/exclude options in windows #1522

patak-dev opened this issue Jan 13, 2021 · 3 comments · Fixed by #1693

Comments

@patak-dev
Copy link
Member

Is your feature request related to a problem? Please describe.

@rollup/plugin-replace is failing in windows when using include or exclude options.

Repro from vanilla starter
https://github.com/matias-capeletto/vite-rollup-plugin-replace

Only the a: __REPLACE__ should read a: replaced, because the include option is only listing a.js

Describe the solution you'd like

This plugin is using createFilter from @rollup/pluginutils. I think this issue may be related to #1521, the filter ends up comparing normalized paths to regular resolved windows paths that include the drive.

A lot of the official rollup plugins and I think other community plugins are using createFilter, and exposing include and exclude options, so it would be great if there is a way to support this pattern.

Additional context

vite version: 2.0.0-beta.27
Operating System: Windows 10 Home, 10.0.18363 N/A Build 18363
Node version: v15.5.0
Package manager and version: yarn v1.22.10

@leiyue
Copy link

leiyue commented Jan 15, 2021

The following command solved the problem.

pnpm install --save-dev react

@patak-dev
Copy link
Member Author

I created another repro for the same issue, but using @rollup/plugin-strip. This one is more interesting because the issue appears with the default values, that for include it is '**/*.js

Here is the repro:
https://github.com/matias-capeletto/vite-rollup-plugin-strip

The issue again is that in Windows Vite is normalizing paths differently from what rollup plugins expect.

Rollup plugins and utilities are normalizing paths by changing the slashes to posix in all systems, but it is not removing the drive ("C:") from the paths, as Vite is doing. Here is the rollup/pluginutils normalizePath implementation:

const normalizePath: NormalizePath = function(filename: string) {
  return filename.split(win32.sep).join(posix.sep);
};

And here is where it is being used to normalize the paths in createFilter.

If a regex is used for include, the matcher works, but this could be error-prone.

  plugins: [
    {
      ...strip({ include: /\**\/*.js/ }),
      apply: "build"
    }
  ]

Would it be possible to re-evalute the way Vite is normalizing paths for the ids? If the drive part is not removed in windows, matching the way normalization works for rollup plugins, I think this could resolve a lot of compat issues.

@patak-dev
Copy link
Member Author

Would it be possible to re-evalute the way Vite is normalizing paths for the ids? If the drive part is not removed in windows, matching the way normalization works for rollup plugins, I think this could resolve a lot of compat issues.

@rollup/plugin-alias is also removing the volume. I see that I need more context to understand why there is an issue here.

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

Successfully merging a pull request may close this issue.

3 participants