Provide mechanism to exclude Mirage from production build for create-react-app projects
See original GitHub issueMirage and Faker are both included in the production bundles for create-react-app
projects, ballooning the vendor package size. create-react-app
does not expose a mechanism to register Webpack externals.
I’m working to investigate workarounds, but it would be nice to have a documented solution for this case because a large portion of the web community uses create-react-app
.
For my use case, my gzipped vendor bundle is increased in size by over 420% when adding the Mirage server entry point.
File sizes after gzip:
469.38 KB (+379.25 KB) build/static/js/2.6b4bd9ed.chunk.js
13.57 KB (+4.92 KB) build/static/js/main.6d95a494.chunk.js
814 B build/static/css/main.7fd419d7.chunk.css
813 B build/static/js/runtime-main.0fd92631.js
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (8 by maintainers)
Top Results From Across the Web
Exclude Mirage from Vue CLI production builds
Since Mirage is a development tool, you should configure Vue CLI to exclude it when building your app for production. This keeps the...
Read more >How can I exclude React Refresh from the Create- ...
After looking at react-refresh, if the environment is in production, it throws an error that it shouldn't be included. I have setup a...
Read more >How To Exclude Specific Files From Vue-Cli-3 Build?
Installing Mirage js; Scenario; API mocking with Mirage Js On webpackbased projects createreactapp Exclude Mirage from Vue CLI production builds.
Read more >Ember.js Octane Edition
With Octane, Ember is a framework for rapidly building high quality ... For comparison, create-react-app always builds in production mode to ...
Read more >Experts for omit lodash
Name Score News
GitHub 85.1 8
Dave Gibbons Ltd. 68.8 3
Conflict Resolution 54.2 2
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have a workaround that utilizes code splitting. I simply asynchronously import my application’s Mirage server initialization module, causing the relevant dependencies and imports to be built into a separate bundle chunk. This chunk will not be requested in production.
I have not yet verified whether this is optimized in terms of Mirage/Faker/etc. all being packaged into the same bundle with no production dependencies, but it appears to greatly mitigate the issue.
Here is an excerpt from my
index.tsx
for anyone curious about how this looks in the application source.Hi @samselikoff,
I might completely misunderstand how this works, but my file structure looks like this:
index.js
server.ts
When I build it like this, Mirage is not excluded from the bundle. I have to wrap
new Server
explicitly with ‘development’ to make it excluded from the bundle. server.tsAnd still,
faker js
data (that is referenced insideloadData
, comes from a local npm package of mine) is still included in the final bundle. How does this works exactly?Thanks for miragejs, awesome tool!