Install plug-in:

yarn add -D rollup-plugin-monaco-editor-nls
Copy the code

Add plugin vite.config.ts:

Vite preload function, need to use esbuildPluginMonacoEditorNls in development phase

import { defineConfig } from "vite";
import monacoEditorNlsPlugin, {
    Languages,
    esbuildPluginMonacoEditorNls,
} from "rollup-plugin-monaco-editor-nls";
const is_dev = process.env.NODE_ENV === "development";

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        alias: {
            "@": resolve("./src"),}},build: {
        sourcemap: true,},optimizeDeps: {
        esbuildOptions: {
            plugins: [
                esbuildPluginMonacoEditorNls({ locale: Languages.zh_hans }),
            ],
        },
    },
    plugins: [!is_dev && monacoEditorNlsPlugin({ locale: Languages.zh_hans })],
});
Copy the code

Github address welcome to star