diff --git a/package.json b/package.json index 8d6f468..0b78fb7 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "vite-plugin-imagemin": "^0.5.3", "vite-plugin-inspect": "^0.7.12", "vite-plugin-manifest-sri": "^0.1.0", + "vite-plugin-minify": "^1.5.2", "vite-plugin-pages": "^0.28.0", "vite-plugin-pages-sitemap": "^1.4.5", "vite-plugin-pwa": "^0.14.0", diff --git a/vite.config.ts b/vite.config.ts index a8124ed..58c0cb7 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -19,12 +19,24 @@ import { createHtmlPlugin } from 'vite-plugin-html'; import manifestSRI from 'vite-plugin-manifest-sri'; import { viteCommonjs } from '@originjs/vite-plugin-commonjs'; import { esbuildCommonjs } from '@originjs/vite-plugin-commonjs'; +import { ViteMinifyPlugin } from 'vite-plugin-minify' +import { dependencies } from './package.json'; const routes = () => import(/* webpackChunkName: "jsRoutes" */ 'resources/js/router/routes.js'); const fs = require('node:fs'); +function renderChunks(deps: Record) { + let chunks = {}; + Object.keys(deps).forEach((key) => { + if (['vue', 'vue-router', 'vue-loader'].includes(key)) return; + chunks[key] = [key]; + }); + return chunks; +} + + export default ({ mode }) => { process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }; let SentryPlugin = null; @@ -141,6 +153,9 @@ export default ({ mode }) => { modulePreload: { polyfill: true, }, + commonjsOptions: { + include: [/node_modules/] + }, }, plugins: [ viteStaticCopy({ @@ -244,7 +259,6 @@ export default ({ mode }) => { }, ], }), - manifestSRI(), vue({ template: { transformAssetUrls: { @@ -350,10 +364,15 @@ export default ({ mode }) => { navigateFallback: 'index.html', }, }), + manifestSRI(), createHtmlPlugin({ minify: true, entry: 'resources/js/app.js', }), + ViteMinifyPlugin({ + minifyCSS: true, + removeComments: true, + }), viteCommonjs(), SentryPlugin, InspectPlugin,