Repository navigation
Build with minify is adding the character "$" #20711
Replies: 2 comments
|
You can keep identifier mangling enabled while reserving those names with Terser. Install it with build: {
// Keep your existing lib/outDir/rollupOptions settings.
minify: isLocal ? false : 'terser',
terserOptions: {
mangle: {
reserved: ['$', 'jQuery'],
},
},
},The options in your Also, ES library builds can retain whitespace to preserve annotations used for tree-shaking; formatting alone is not a reliable test of whether the bundle was optimized. One diagnostic point: your library output is References: Vite build.minify / build.terserOptions, Terser mangle options. |
|
Esbuild picks The quick fix is to keep minification but disable only identifier renaming: export default defineConfig({
esbuild: { minifyIdentifiers: false }
})Costs a bit of bundle size, but no The more durable fix: don't rely on a global — |
Uh oh!
There was an error while loading. Please reload this page.
I'm using vite accross multiple repositories, and after a few months I finally started having some problems due to the variable $ of JQuery. How can I avoid 'esbuild' or 'terser' to not minify using $ or jquery? I already tried multiple things, but without success.
For now, I have the following configuration:
`const { defineConfig } = require('vite');
const path = require('path');
module.exports = defineConfig(({ mode }) => {
const isLocal = mode.includes('.local');
// Define widget configurations
const widgetConfigs = {
'list-packages': {
entry: 'wwwroot/components/catalog/catalog-management/list-packages/main.js',
name: 'ListPackagesWidget',
outDir: 'wwwroot/components/catalog/catalog-management/list-packages'
},
'add-package': {
entry: 'wwwroot/components/catalog/catalog-management/add-package/main.js',
name: 'AddPackageWidget',
outDir: 'wwwroot/components/catalog/catalog-management/add-package'
},
'edit-package': {
entry: 'wwwroot/components/catalog/catalog-management/edit-package/main.js',
name: 'EditPackageWidget',
outDir: 'wwwroot/components/catalog/catalog-management/edit-package'
}
};
// Get widget name from mode (remove .local suffix if present)
const widgetName = mode.replace('.local', '');
const config = widgetConfigs[widgetName] || widgetConfigs['list-packages'];
return {
resolve: {
alias: {
'@utils': path.resolve(__dirname, 'wwwroot/components/catalog/shared/utils'),
'@managers': path.resolve(__dirname, 'wwwroot/components/catalog/shared/managers')
}
},
server: {
port: 8080,
open: 'wwwroot/components/catalog'
},
build: {
lib: {
entry: config.entry,
name: config.name,
fileName: 'init',
formats: ['es']
},
outDir: config.outDir,
emptyOutDir: false,
sourcemap: false,
minify: !isLocal,
rollupOptions: {
output: {
entryFileNames: 'init.js'
}
},
},
esbuild: {
target: 'es2024',
legalComments: 'none',
minifyIdentifiers: false,
keepNames: true,
minifySyntax: true,
minifyWhitespace: true
}
};
}); `
This works, but the minify is not really a minify. It's jsut a bundle. How can we solve this?
All reactions