Open tomatobybike opened 2 years ago
Install this library
yarn add @esbuild-plugins/node-globals-polyfill
add this import to your vite.config.js
and add this in your vite.config.js
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
export default defineConfig({
// ...other config settings
optimizeDeps: {
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true
})
]
}
}
}
Wow rarely I find solutions that work straight away, thanks @tomatobybike !
Would be nicer if this library was compatible with the browser to begin with, or add a browser build defined in the package.json
It seems optimizeDeps isn't run on vite build
...
vite-plugin-node-polyfills should solve both dev/build problem. See: https://www.npmjs.com/package/vite-plugin-node-polyfills
if use nuxtjs, see https://github.com/nuxt/nuxt/issues/25016
Install this library
yarn add @esbuild-plugins/node-globals-polyfill
add this import to your vite.config.js
and add this in your vite.config.js
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill' export default defineConfig({ // ...other config settings optimizeDeps: { esbuildOptions: { // Node.js global to browser globalThis define: { global: 'globalThis' }, // Enable esbuild polyfill plugins plugins: [ NodeGlobalsPolyfillPlugin({ buffer: true }) ] } } }
Yes this works but when I checked the matter, it has
content
as html data with also includes the metadeta which I included in the--- ... ---
and the data field was an empty object.
when i use gray-matter in vite react project, found this error:
how to fix