npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-monaco-editor-new

v1.1.3

Published

A vite plugin for the Monaco Editor

Downloads

159

Readme

Vite Plugin Monaco Editor

A plugin to simplify loading the Monaco Editor with vite.

  • It uses Vite specific plugin hooks: configResolved, configureServer, transformIndexHtml.
  • It uses esbuild to bundle worker in the node_modules/.monaco directory, via the server.middlewares proxy http server for the bundle worker.

Installing

// make sure you have it installed monaco-editor.

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

// or
npm install -D vite-plugin-monaco-editor monaco-editor

// or
pnpm install -D vite-plugin-monaco-editor monaco-editor

Using

  • vite.config.ts:
import { defineConfig } from 'vite';
import monacoEditorPlugin from 'vite-plugin-monaco-editor';

export default defineConfig({
  plugins: [monacoEditorPlugin()],
});

Import all monaco functions

  • index.ts:
import * as monaco from 'monaco-editor';

monaco.editor.create(document.getElementById('container'), {
  value: 'console.log("Hello, world")',
  language: 'javascript',
});

Import part of monaco functions

The import * as monaco from 'monaco-editor' is import all features and languages of the Monaco Editor. Assume you only need part of the features and languages:

  • customMonaco.ts
import 'monaco-editor/esm/vs/editor/editor.all.js';
import 'monaco-editor/esm/vs/editor/standalone/browser/accessibilityHelp/accessibilityHelp.js';

import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';

export { monaco };

The Complete list of imports: customMonaco.ts

  • index.ts
import { monaco } from './customMonaco.ts';
monaco.editor.create(document.getElementById('container'), {
  value: 'console.log("Hello, world")',
  language: 'javascript',
});

Options

  • languageWorkers (string[]) - include only a subset of the languageWorkers supported.

    • default value: ['editorWorkerService', 'css', 'html', 'json', 'typescript'].
    • Assuming only use css worker(editorWorkerService is must include base worker), you can set ['editorWorkerService', 'css']
  • customWorkers (IWorkerDefinition[]) - include your custom worker.

    • default value: []
    • example value: [{label: "graphql", entry: "monaco-graphql/esm/graphql.worker"}], The entry is relative path in the node_modules Or you can set absolute path.
  • publicPath (string) - custom public path for worker scripts, overrides the public path from which files generated by this plugin will be served. Or you can set CDN e.g https://unpkg.com/[email protected]/cdn

    • default value: monacoeditorwork
  • globalAPI (boolean) - specifies whether the editor API should be exposed through a global monaco object or not. This option is applicable to 0.22.0 and newer version of monaco-editor. Since 0.22.0, the ESM version of the monaco editor does no longer define a global monaco object unless global.MonacoEnvironment = { globalAPI: true } is set (change log).

    • default value: false.
  • customDistPath ((root: string, buildOutDir: string, base: string) => string) - Custom callback returns the worker path

  • forceBuildCDN (boolean) - If you use CDN, the build is skipped by default. Set to true if you want to generate woker

    • default value: false

Some languages share the same web worker. If one of the following languages is included, you must also include the language responsible for instantiating their shared worker:

| Language | Instantiator | | ---------- | ------------ | | javascript | typescript | | handlebars | html | | scss, less | css |