Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

vue3, vite and django

//in django-app
pip install django-vite

//in django-app settings.py
INSTALLED_APPS = [
    ...
    'django_vite',
    ...
]

//in vue_app package.json
"scripts: {
  ...
  "build": "vue-tsc --noEmit && npm run build:client && npm run build:server",
  "build:client": "vite build --ssrManifest --outDir dist/client",
  "build:server": "vite build --ssr src/entry-server.js --outDir dist/server",
  ...
}
  
//in vue_app vite.config.ts
export default defineConfig({
  ...
    build: {
    // generate manifest.json in outDir
    manifest: true,
      // overwrite default .html entry
    outDir: resolve('<path-to-your-static-file>'),
    assetsDir: '',
    manifest: true,
    emptyOutDir: true,
    target: 'es2015',
    rollupOptions: {
      input: {
        main: resolve('<path-to-your-static-file>'),
      },
      output: {
        chunkFileNames: undefined,
      },
    },
  }
})

//in vue-app main.ts
import 'vite/modulepreload-polyfill'; PLEASE READ THIS "this will lead to Uncaught ReferenceError: __VITE_IS_MODERN__ is not defined" error
SO DO NOT IMPORT!

//in django-app settings.py
# Where ViteJS assets are built.
DJANGO_VITE_ASSETS_PATH = BASE_DIR / "static" / "dist"

# If use HMR or not.
DJANGO_VITE_DEV_MODE = DEBUG

# Name of static files folder (after called python manage.py collectstatic)
STATIC_ROOT = BASE_DIR / "collectedstatic"

# Include DJANGO_VITE_ASSETS_PATH into STATICFILES_DIRS to be copied inside
# when run command python manage.py collectstatic
STATICFILES_DIRS = [DJANGO_VITE_ASSETS_PATH]


  
Comment

PREVIOUS NEXT
Code Example
Typescript :: tsc.ps1 cannot be loaded because running scripts is disabled on this system 
Typescript :: aws sts assume-role example 
Typescript :: node typescript 
Typescript :: handling ajax requests in django 
Typescript :: Does not use passive listeners to improve scrolling performance 
Typescript :: python code find digits 
Typescript :: how to display server count on discord.js 
Typescript :: Give each of the radio and checkbox inputs the value attribute. Use the input label text, in lowercase, as the value for the attribute. 
Typescript :: ngclass stackoverflow 
Typescript :: typescript how to add a property to an object 
Typescript :: typescript cannot find name console 
Typescript :: yup type validation error message 
Typescript :: typescript enum to array 
Typescript :: How to do Email validation using Regular expression in Typescript 
Typescript :: typescript get all enum values 
Typescript :: list of environment python 
Typescript :: class validator enum 
Typescript :: __redux_devtools_extension_compose__ typescript 
Typescript :: typescript function example array arg 
Typescript :: how are uv rays produced 
Typescript :: vue save page elements to pdf 
Typescript :: typescript endless loop 
Typescript :: angular typescript refresh page 
Typescript :: write a C proogram to find the roots of quadratic equation 
Typescript :: limit characters and have three dots after in angular 6 
Typescript :: what will the type of empty object in typescript 
Typescript :: enable anchor scrolling angular 
Typescript :: render async function to component 
Typescript :: create user properties firebase 
Typescript :: typescript if statement 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =