zjt_home_vite-plugin-monaco-editor-nls
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Vite Plugin monaco-editor-nls

Install:

yarn add -D vite-plugin-monaco-editor-nls

Using

Add this plugin in vite.config.ts:

import MonacoEditorNlsPlugin, {
    esbuildPluginMonacoEditorNls,
    Languages,
} from 'vite-plugin-monaco-editor-nls';

// https://vitejs.dev/config/
export default defineConfig({
    resolve: {
        alias: {
            '@': resolve('./src'),
        },
    },
    build: {
        sourcemap: true,
    },
    optimizeDeps: {
        /** vite >= 2.3.0 */
        esbuildOptions: {
            plugins: [
                esbuildPluginMonacoEditorNls({
                    locale: Languages.zh_hans,
                }),
            ],
        },
    },
    plugins: [
        reactRefresh(),
        MonacoEditorNlsPlugin({locale: Languages.zh_hans}),
    ],
});

Joying it

pnpm run example

Using custom locale

It dependency on vscode-loc to get the locales.

  • First

pnpm add -D git+https://github.com/microsoft/vscode-loc.git

If this is slow, you can try to copy a copy using gitlab.

like this pnpm add -D git+https://jihulab.com/james-curtis/vscode-loc

  • Then
import reactRefresh from '@vitejs/plugin-react-refresh';
import {resolve} from 'path';
import {defineConfig} from 'vite';
import MonacoEditorNlsPlugin, {
    esbuildPluginMonacoEditorNls,
    Languages,
} from 'vite-plugin-monaco-editor-nls';
import Inspect from 'vite-plugin-inspect';

const zh_CN = require('vscode-loc.git/i18n/vscode-language-pack-zh-hans/translations/main.i18n.json')

// https://vitejs.dev/config/
export default defineConfig({
    base: './',
    resolve: {
        alias: {
            '@': resolve('./src'),
        },
    },
    build: {
        sourcemap: true,
    },
    optimizeDeps: {
        /** vite 版本需要大于等于2.3.0 */
        esbuildOptions: {
            plugins: [
                esbuildPluginMonacoEditorNls({
                    locale: Languages.zh_hans,
                    /**
                     * The weight of `localedata` is higher than that of `locale`
                     */
                    localeData: zh_CN.contents
                }),
            ],
        },
    },
    plugins: [
        reactRefresh(),
        Inspect(),
        MonacoEditorNlsPlugin({
            locale: Languages.zh_hans,
            /**
             * The weight of `localedata` is higher than that of `locale`
             */
            localeData: zh_CN.contents
        }),
    ],
});

Question

  1. Incomplete localization

try using custom locale , please

Dependencies (0)

    Dev Dependencies (7)

    Package Sidebar

    Install

    npm i zjt_home_vite-plugin-monaco-editor-nls

    Weekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    19 kB

    Total Files

    4

    Last publish

    Collaborators

    • zhangjintong