I need to build Vue project into Docker that bundling by Vite
Front and backend will be deployed on the same domain
Because of that I have to set baseURL /front.
Here my files to build project
vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path';
import { visualizer } from "rollup-plugin-visualizer";
import { quasar, transformAssetUrls } from '@quasar/vite-plugin';
export default defineConfig({
plugins: [
vue({
template: { transformAssetUrls }
}),
visualizer({ template: "list" }),
quasar({
sassVariables: 'src/quasar-variables.sass'
}),
],
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
},
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
},
css: {
preprocessorOptions: {
scss: {
additionalData: `
@import "@/assets/styles/global.scss";
`,
}
}
},
server: {
port: 8080,
},
base: "/front/",
})
Dockerfile
FROM node:20-alpine AS build
WORKDIR /var/www/app
COPY . .
RUN npm install
RUN npm run build
# Create Nginx server
FROM nginx:1.24.0-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /var/www/app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
nginx.conf
types {
application/javascript js;
text/javascript js;
}
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html?$args;
}
}
All I found about this task said me that my file is correct.
One time I gave up and asked GPT, but he gave the same output
But I’m get this error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.