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

[Vite] fileReplacements is not working #13246

Closed
nodegin opened this issue Nov 18, 2022 · 5 comments · Fixed by #13255
Closed

[Vite] fileReplacements is not working #13246

nodegin opened this issue Nov 18, 2022 · 5 comments · Fixed by #13255
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@nodegin
Copy link
Contributor

nodegin commented Nov 18, 2022

Current Behavior

The fileReplacements option is not working

Expected Behavior

It should be able to resolve the file, but currently it won't resolve the file for replacement correctly

Github Repo

No response

Steps to Reproduce

  1. Specify the fileReplacements in project.json
          "fileReplacements": [
            {
              "replace": "apps/core/src/config/config.staging.ts",
              "with": "apps/core/src/config/config.production.ts"
            }
          ],
  1. Edit the @nrwl/vite/plugins/rollup-replace-files.plugin.js and add some log

Screen Shot 2022-11-18 at 20 33 20

  1. Build the app
    npx nx build core --configuration production --verbose --skip-nx-cache

  2. Observe the log

Screen Shot 2022-11-18 at 20 33 50

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : darwin arm64
   npm  : 8.11.0
   
   nx : 15.2.0
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.2.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.2.0
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.2.0
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.2.0
   @nrwl/js : 15.2.0
   @nrwl/linter : 15.2.0
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.2.0
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.2.0
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.2.0
   @nrwl/web : 15.2.0
   @nrwl/webpack : 15.2.0
   @nrwl/workspace : 15.2.0
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
   	 @nrwl/vite: 15.2.0

Failure Logs

No response

Additional Information

No response

@mandarini mandarini added the scope: bundlers Issues related to webpack, rollup label Nov 18, 2022
@mandarini mandarini self-assigned this Nov 18, 2022
mandarini added a commit to mandarini/nx that referenced this issue Nov 18, 2022
@nodegin
Copy link
Contributor Author

nodegin commented Nov 18, 2022

@mandarini Sorry I tested your code but I found the problem was the source being undefined
I added this line:
console.log('source', source);
And this is the result:

source /Users/nodegin/Desktop/cms-fe/react
source /Users/nodegin/Desktop/cms-fe/react-dom/client
source /Users/nodegin/Desktop/cms-fe/react
source /Users/nodegin/Desktop/cms-fe/react-dom/client

From my side, there was no modules coming from the apps folder,
did I missed something on the usage?

@nodegin
Copy link
Contributor Author

nodegin commented Nov 18, 2022

So I created a PR #13261 by changing the code I got it working correctly.

Screen Shot 2022-11-19 at 2 32 53

Screen Shot 2022-11-19 at 2 33 26

@nodegin
Copy link
Contributor Author

nodegin commented Nov 18, 2022

Turns out I found the existing "rollup-plugin-replace-files" is a Vite Plugin... not rollup
that's why it's not working expected, it should be moved to vite config instead

@mandarini
Copy link
Member

mandarini commented Nov 21, 2022

@nodegin yep, that's the main issue! :) I moved it out of rollup, but made sure to test the endsWith instead of full match, just to make sure! :) thank you so much for looking into it, too!

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
2 participants