The dev mode using npm run dev
, the release mode using npm build
How could i know that it's currently built on dev mode or not in the code, for example:
<script>
import {onMount} from 'svelte';
onMount(function(){
if(DEVMODE) { // --> what's the correct one?
console.log('this is x.svelte');
}
})
</script>
Not sure about the correct method. I share what I did on my project.
rollup.config.js
import replace from "@rollup/plugin-replace"; const production = !process.env.ROLLUP_WATCH;
plugins:[ ]
block add thisreplace({ isProduction: production, }),
rollup.config.js will look like this.
},
plugins: [
replace({
isProduction: production,
}),
svelte({
isProduction
inside components .
if (!isProduction){ console.log('Developement Mode'); }
If you are using sveltekit:
import { dev } from '$app/env';
if (dev) {
//do in dev mode
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With