節點 polyfill 在 rollup/vite 上不適合我們。我們需要切換到 webpack。
有沒有關于如何在 webpack 中使用 sveltekit 的官方檔案?
這是我們的svelte.config.js檔案:
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
import path from 'path';
// import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import dotenv from 'dotenv-flow';
dotenv.config();
const config = {
preprocess: preprocess(),
kit: {
adapter: adapter({
// default options are shown
pages: 'build',
assets: 'build',
fallback: 'index.html',
precompress: false
}),
vite: {
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
}
// Enable esbuild polyfill plugins
// plugins: [
// NodeGlobalsPolyfillPlugin({
// buffer: true,
// global: true,
// process: true,
// url: true,
// assert: true,
// crypto: true,
// http: true,
// https: true,
// os: true,
// stream: true
// })
// ]
}
},
resolve: {
alias: {
$components: path.resolve('./src/components'),
$stores: path.resolve('./src/stores'),
$api: path.resolve('./src/api'),
$node: path.resolve('./node_modules')
}
},
build: {
minify: false
}
}
}
};
export default config;
uj5u.com熱心網友回復:
你不能切換它。SvelteKit 高度依賴 Vite,以至于它甚至有可能在某個時候作為 Vite 插件發布。
如果你真的用盡了 Vite 的選項并決定必須使用 Webpack,一個選項是將所有需要它的代碼隔離到一個單獨的包中,然后你可以與 Webpack 預捆綁并從 SvelteKit 應用程式中使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/482266.html
