import { version } from 'quasar/package.json'
import { normalizePath } from 'vite'

export default ({ runMode, sassVariables }) => {
  const viteCfg = {
    define: {
      __QUASAR_VERSION__: `'${ version }'`,
      __QUASAR_SSR__: false,
      __QUASAR_SSR_SERVER__: false,
      __QUASAR_SSR_CLIENT__: false,
      __QUASAR_SSR_PWA__: false
    },

    optimizeDeps: {
      exclude: [ 'quasar' ]
    }
  }

  if (runMode === 'ssr-client') {
    Object.assign(viteCfg.define, {
      __QUASAR_SSR__: true,
      __QUASAR_SSR_CLIENT__: true
    })
  }
  else if (runMode === 'ssr-server') {
    Object.assign(viteCfg.define, {
      __QUASAR_SSR__: true,
      __QUASAR_SSR_SERVER__: true
    })
  }

  if (sassVariables) {
    const sassImportCode = (
      (typeof sassVariables === 'string' ? `@import '${ normalizePath(sassVariables) }'\n` : '')
      + `@import 'quasar/src/css/variables.sass'\n`
    )

    viteCfg.css = {
      preprocessorOptions: {
        sass: { additionalData: sassImportCode },
        scss: { additionalData: sassImportCode }
      }
    }
  }

  return viteCfg
}

@@ -750,15 +750,65 @@
 e = 
-(
+%5B %60@import 'quasar/src/css/variables.sass'%60, '' %5D%0A
 %0A    
- 
+if
  (ty
@@ -842,11 +842,41 @@
 ing'
- ? 
+) %7B%0A      sassImportCode.unshift(
 %60@im
@@ -919,75 +919,16 @@
 ) %7D'
-%5Cn%60 : '')%0A      + %60@import 'quasar/src/css/variables.sass'%5Cn%60%0A    )
+%60)%0A    %7D
 %0A%0A  
@@ -1020,16 +1020,27 @@
 portCode
+.join('%5Cn')
  %7D,%0A    
@@ -1081,16 +1081,28 @@
 portCode
+.join(';%5Cn')
  %7D%0A     

support SCSS imports (#11105)