我安装了 Laravel 并且有这样的配置
` 从 'vite' 导入 {defineConfig}; 从“laravel-vite-plugin”导入 laravel;
export default defineConfig(({ mode }) => {
return {
plugins: [
laravel({
input: [
/// Heaps of files are being connected
],
refresh: true,
})
],
build: {
outDir: 'public/build',
minify: 'esbuild',
modulePreload: false,
polyfillModulePreload: false,
sourcemap: mode !== 'production',
terserOptions: {
compress: {
drop_console: mode === 'production',
},
output: {
comments: mode === 'production',
},
},
},
}
});
`
我想要编译并输出一个文件,但现在我有一个具有此连接的文件
@vite(['resources/js/client/pages/client/sale/sale.js'])
我希望他成为唯一连接的人,但我已经无法连接他了,仅此而已
<link rel="modulepreload" href="https://hitno.local/build/assets/constant-jYRDAREv.js"> <link rel="modulepreload" href="https://hitno.local/build/assets/init-swiper-CYD-sbV2.js"> <link rel="modulepreload" href="https://hitno.local/build/assets/pagination-BSD8aAhp.js"> <script type="module" src="https://hitno.local/build/assets/sale-CrTjuH8L.js"></script>
我希望我根本没有预加载模块,而只是连接我指定的一个文件
我试图自己弄清楚,但除了模块Preload和polyfillModulePreload参数之外,我并没有真正找到任何东西,但它们没有帮助
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig(({ mode }) => {
return {
plugins: [
laravel({
input: [
'resources/js/client/pages/client/sale/sale.js', // specify only the file you want to compile
],
refresh: true,
}),
],
build: {
outDir: 'public/build',
minify: 'esbuild',
modulePreload: false,
polyfillModulePreload: false,
sourcemap: mode !== 'production',
rollupOptions: {
output: {
manualChunks: undefined, // disables code splitting
},
},
terserOptions: {
compress: {
drop_console: mode === 'production',
},
output: {
comments: mode === 'production',
},
},
},
};
});
说明
• input: Specify only the file you want as the main entry point.
• manualChunks: undefined: By setting manualChunks to undefined, you’re disabling Vite’s automatic chunking behavior, which will prevent additional chunks from being generated.
• modulePreload and polyfillModulePreload: false: This prevents Vite from generating additional <link rel="modulepreload"> tags in the HTML output.
通过此设置,Vite 应该将所有代码编译到单个输出文件中,而不生成额外的预加载或模块块。这将为您提供指定条目文件的单个标签。让我知道这是否达到了您想要的结果!