This is my first question here.
I have two scripts: script.js and script-dev.js
Both scripts are located in 'static' folder(I am using NUXTJS)
Now, when webpack production build is used, ONLY script.js should be used and script-dev.js should be excluded/not used (sorry if i am using any incorrect term)
Similarly, for webpack development build, ONLY script-dev.js should be used and script.js should be excluded/not used.
(I am doing so because I will be using two diff API Urls in both files and script-dev.js will be used only for testing code in development. )
I have a nuxt.config.js file in root folder.
Can anyone please help me how can I modify the nuxt.config.js (or any other way you know) to achieve the above result.
here is my current nuxt.config.js and I have extended the webpack config as shown below (sorry for the improper formatting):
export default {
telemetry: false,
mode: 'universal',
server: {
host: '0.0.0.0',
port: 3000,
},
env: {
API_URL: process.env.API_URL,
},
serverMiddleware: [
{
path: '/r',
handler: '~/api/redirector.js',
},
],
build: {
extend(config, ctx) {
if (ctx.isDev) {
config.module.rules.push({
test: /.js$/,
exclude: [path.resolve(__dirname, 'static/script.js')],
})
} else {
config.module.rules.push({
test: /.js$/,
exclude: [path.resolve(__dirname, 'static/script-dev.js')],
})
}
},
},
}