Hello I have a requirem…
Hello! I have a requirement, and wanted to ask if this is supported by nx @nrwl/web
I have a service worker file that is located in assets
And I need this file only in development mode (is loaded by process.env.NODE_ENV === 'development' )
When building the application for production, how can I ignore this asset file? (don’t include it in assets)
Thanks in advance!
Responses:
you can override options for the builder by adding attributes to the configurations attribute in your workspace.json
production will be used when running nx build webappname --prod
so all you have to do is add an assets attribute to production and set it to the files you want when not in prod
here’s an example of how I bring different assets in the production bundle (which for me is any bundle not in local)
this example uses @nrwl/angular but the concept and the available options are similar
assets configuration example https://angular.io/guide/workspace-config#assets-configuration
nrwl/web docs <https://nx.dev/angular/plugins/web/builders/build#assets>
Thanks it worked, I also thought of this but didn’t know exactly how build and dev-server work together
Here is a partial config
{
"builder": "@nrwl/web:build",
"options": {
"assets": [
"apps/site-builder/src/favicon.ico",
"apps/site-builder/src/mockServiceWorker.js",
"apps/site-builder/src/assets"
]
},
"configurations": {
"production": {
"assets": [
"apps/site-builder/src/favicon.ico",
"apps/site-builder/src/assets"
]
}
}
}