Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

serving vue3 in 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 :: requests to check is url exists in python using function 
Typescript :: wordpress have_posts not working 
Typescript :: how to run typescript file 
Typescript :: how to get absolute value of elements of list in python 
Typescript :: tweepy stream tweets from user 
Typescript :: python count number of digits in integer 
Typescript :: group objects in javascript 
Typescript :: angular reload component 
Typescript :: how to remove duplcates elements from arraylist 
Typescript :: round up number typescript 
Typescript :: how to display an image in flutter using its filepath 
Typescript :: how to access event.target elements in typescript 
Typescript :: how to put the contents of a file into an array in bash 
Typescript :: how to check if its a character in r 
Typescript :: typescript interface key with another type 
Typescript :: see conda enviroments 
Typescript :: typescript bigint vs number 
Typescript :: how to check if an entry exists in a model django 
Typescript :: How to fix warning "function -- makes the dependencies of useEffect Hook change on every render"? 
Typescript :: react router dom private route typescript 
Typescript :: states on the west coast 
Typescript :: function to find the unique elements from two arrays 
Typescript :: classes in typescript 
Typescript :: ts declare function type 
Typescript :: java write arraylist of objects to file 
Typescript :: angular get user location 
Typescript :: SocketException: An attempt was made to access a socket in a way forbidden by its access permissions. in core 6.0 
Typescript :: amcharts angular universal 
Typescript :: create custom properties for user firebase 
Typescript :: enum in ts 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =