mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 12:45:39 +01:00
Adopt esbuild in monaco-html
This commit is contained in:
parent
9a52545094
commit
c8344afb94
9 changed files with 119 additions and 151 deletions
|
|
@ -6,6 +6,7 @@
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const cp = require('child_process');
|
||||
const esbuild = require('esbuild');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '..');
|
||||
|
||||
|
|
@ -154,6 +155,21 @@ function dts(_source, _destination, namespace) {
|
|||
}
|
||||
exports.dts = dts;
|
||||
|
||||
/**
|
||||
* @param {import('esbuild').BuildOptions} options
|
||||
*/
|
||||
function build(options) {
|
||||
esbuild.build(options).then((result) => {
|
||||
if (result.errors.length > 0) {
|
||||
console.error(result.errors);
|
||||
}
|
||||
if (result.warnings.length > 0) {
|
||||
console.error(result.warnings);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.build = build;
|
||||
|
||||
function getGitVersion() {
|
||||
const git = path.join(REPO_ROOT, '.git');
|
||||
const headPath = path.join(git, 'HEAD');
|
||||
|
|
|
|||
|
|
@ -3,10 +3,9 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const esbuild = require('esbuild');
|
||||
const alias = require('esbuild-plugin-alias');
|
||||
const path = require('path');
|
||||
const { removeDir, tsc, dts } = require('../build/utils');
|
||||
const { removeDir, tsc, dts, build } = require('../build/utils');
|
||||
|
||||
removeDir(`monaco-css/release`);
|
||||
removeDir(`monaco-css/out`);
|
||||
|
|
@ -19,20 +18,6 @@ dts(
|
|||
'monaco.languages.css'
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {import('esbuild').BuildOptions} options
|
||||
*/
|
||||
function build(options) {
|
||||
esbuild.build(options).then((result) => {
|
||||
if (result.errors.length > 0) {
|
||||
console.error(result.errors);
|
||||
}
|
||||
if (result.warnings.length > 0) {
|
||||
console.error(result.warnings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
build({
|
||||
entryPoints: ['src/monaco.contribution.ts', 'src/cssMode.ts', 'src/css.worker.ts'],
|
||||
bundle: true,
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ monaco.languages.registerDocumentSemanticTokensProvider('plaintext', {
|
|||
monaco.editor.defineTheme('myCustomTheme', {
|
||||
base: 'vs',
|
||||
inherit: true,
|
||||
colors: {},
|
||||
rules: [
|
||||
{ token: 'comment', foreground: 'aaaaaa', fontStyle: 'italic' },
|
||||
{ token: 'keyword', foreground: 'ce63eb' },
|
||||
|
|
|
|||
89
monaco-html/build.js
Normal file
89
monaco-html/build.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const alias = require('esbuild-plugin-alias');
|
||||
const path = require('path');
|
||||
const { removeDir, tsc, dts, build } = require('../build/utils');
|
||||
|
||||
removeDir(`monaco-html/release`);
|
||||
removeDir(`monaco-html/out`);
|
||||
|
||||
tsc(`monaco-html/src/tsconfig.json`);
|
||||
|
||||
dts(
|
||||
`monaco-html/out/amd/monaco.contribution.d.ts`,
|
||||
`monaco-html/monaco.d.ts`,
|
||||
'monaco.languages.html'
|
||||
);
|
||||
|
||||
build({
|
||||
entryPoints: ['src/monaco.contribution.ts', 'src/htmlMode.ts', 'src/html.worker.ts'],
|
||||
bundle: true,
|
||||
target: 'esnext',
|
||||
format: 'esm',
|
||||
define: {
|
||||
AMD: false
|
||||
},
|
||||
external: ['monaco-editor-core', '*/htmlMode'],
|
||||
outdir: 'release/esm/',
|
||||
plugins: [
|
||||
alias({
|
||||
'vscode-nls': path.join(__dirname, 'src/fillers/vscode-nls.ts')
|
||||
})
|
||||
]
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {'dev'|'min'} type
|
||||
* @param {string} entryPoint
|
||||
* @param {string} banner
|
||||
*/
|
||||
function buildOneAMD(type, entryPoint, banner) {
|
||||
/** @type {import('esbuild').BuildOptions} */
|
||||
const options = {
|
||||
entryPoints: [entryPoint],
|
||||
bundle: true,
|
||||
target: 'esnext',
|
||||
format: 'iife',
|
||||
define: {
|
||||
AMD: true
|
||||
},
|
||||
external: ['*/htmlMode'],
|
||||
globalName: 'moduleExports',
|
||||
banner: {
|
||||
js: banner
|
||||
},
|
||||
footer: {
|
||||
js: 'return moduleExports;\n});'
|
||||
},
|
||||
outdir: `release/${type}/`,
|
||||
plugins: [
|
||||
alias({
|
||||
'vscode-nls': path.join(__dirname, 'src/fillers/vscode-nls.ts'),
|
||||
'monaco-editor-core': path.join(__dirname, 'src/fillers/monaco-editor-core-amd.ts')
|
||||
})
|
||||
]
|
||||
};
|
||||
if (type === 'min') {
|
||||
options.minify = true;
|
||||
}
|
||||
build(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} entryPoint
|
||||
* @param {string} banner
|
||||
*/
|
||||
function buildAMD(entryPoint, banner) {
|
||||
buildOneAMD('dev', entryPoint, banner);
|
||||
buildOneAMD('min', entryPoint, banner);
|
||||
}
|
||||
|
||||
buildAMD(
|
||||
'src/monaco.contribution.ts',
|
||||
'define("vs/language/html/monaco.contribution",["vs/editor/editor.api"],()=>{'
|
||||
);
|
||||
buildAMD('src/htmlMode.ts', 'define("vs/language/html/htmlMode",["vs/editor/editor.api"],()=>{');
|
||||
buildAMD('src/htmlWorker.ts', 'define("vs/language/html/htmlWorker",[],()=>{');
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"scripts": {
|
||||
"watch": "../node_modules/.bin/tsc -p ./src --watch",
|
||||
"prepublishOnly": "node ./scripts/build"
|
||||
"prepublishOnly": "node ./build"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const esbuild = require('esbuild');
|
||||
const alias = require('esbuild-plugin-alias');
|
||||
const path = require('path');
|
||||
const cp = require('child_process');
|
||||
const { removeDir, tsc, dts } = require('../../build/utils');
|
||||
|
||||
removeDir(`monaco-html/release`);
|
||||
removeDir(`monaco-html/out`);
|
||||
|
||||
tsc(`monaco-html/src/tsconfig.json`);
|
||||
|
||||
dts(
|
||||
`monaco-html/out/amd/monaco.contribution.d.ts`,
|
||||
`monaco-html/monaco.d.ts`,
|
||||
'monaco.languages.html'
|
||||
);
|
||||
|
||||
esbuild
|
||||
.build({
|
||||
entryPoints: ['src/htmlMode.ts', 'src/html.worker.ts', 'src/monaco.contribution.ts'],
|
||||
bundle: true,
|
||||
target: 'esnext',
|
||||
format: 'esm',
|
||||
external: ['monaco-editor-core', '*/htmlMode'],
|
||||
outdir: 'release/esm/',
|
||||
plugins: [
|
||||
alias({
|
||||
'vscode-nls': path.join(__dirname, '../src/fillers/vscode-nls.ts')
|
||||
})
|
||||
]
|
||||
})
|
||||
.then((result) => {
|
||||
if (result.errors.length > 0) {
|
||||
console.error(result.errors);
|
||||
}
|
||||
if (result.warnings.length > 0) {
|
||||
console.error(result.warnings);
|
||||
}
|
||||
});
|
||||
|
||||
cp.spawnSync(process.execPath, [path.join(__dirname, './bundle.js')], {
|
||||
stdio: 'inherit',
|
||||
stderr: 'inherit'
|
||||
});
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
const requirejs = require('requirejs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const terser = require('terser');
|
||||
const { getBundledFileHeader } = require('../../build/utils');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..', '..');
|
||||
|
||||
const BUNDLED_FILE_HEADER = getBundledFileHeader();
|
||||
|
||||
bundleOne('monaco.contribution');
|
||||
bundleOne('htmlMode', ['vs/language/html/monaco.contribution']);
|
||||
bundleOne('htmlWorker');
|
||||
|
||||
function bundleOne(moduleId, exclude) {
|
||||
requirejs.optimize(
|
||||
{
|
||||
baseUrl: 'out/amd/',
|
||||
name: 'vs/language/html/' + moduleId,
|
||||
out: 'release/dev/' + moduleId + '.js',
|
||||
exclude: exclude,
|
||||
paths: {
|
||||
'vs/language/html': REPO_ROOT + '/monaco-html/out/amd',
|
||||
'vs/language/html/fillers/monaco-editor-core':
|
||||
REPO_ROOT + '/monaco-html/out/amd/fillers/monaco-editor-core-amd'
|
||||
},
|
||||
optimize: 'none',
|
||||
packages: [
|
||||
{
|
||||
name: 'vscode-html-languageservice',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-html-languageservice/lib/umd'),
|
||||
main: 'htmlLanguageService'
|
||||
},
|
||||
{
|
||||
name: 'vscode-languageserver-types',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'vscode-languageserver-textdocument',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-textdocument/lib/umd'),
|
||||
main: 'main'
|
||||
},
|
||||
{
|
||||
name: 'vscode-uri',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
||||
main: 'index'
|
||||
},
|
||||
{
|
||||
name: 'vscode-nls',
|
||||
location: path.join(REPO_ROOT, 'monaco-html/out/amd/fillers'),
|
||||
main: 'vscode-nls'
|
||||
}
|
||||
]
|
||||
},
|
||||
async function (buildResponse) {
|
||||
const devFilePath = path.join(REPO_ROOT, 'monaco-html/release/dev/' + moduleId + '.js');
|
||||
const minFilePath = path.join(REPO_ROOT, 'monaco-html/release/min/' + moduleId + '.js');
|
||||
const fileContents = fs.readFileSync(devFilePath).toString();
|
||||
console.log();
|
||||
console.log(`Minifying ${devFilePath}...`);
|
||||
const result = await terser.minify(fileContents, {
|
||||
output: {
|
||||
comments: 'some'
|
||||
}
|
||||
});
|
||||
console.log(`Done minifying ${devFilePath}.`);
|
||||
try {
|
||||
fs.mkdirSync(path.join(REPO_ROOT, 'monaco-html/release/min'));
|
||||
} catch (err) {}
|
||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -5,8 +5,4 @@
|
|||
|
||||
// Resolves with the global monaco API
|
||||
|
||||
declare var define;
|
||||
|
||||
define([], function () {
|
||||
return (<any>self).monaco;
|
||||
});
|
||||
export = (<any>self).monaco;
|
||||
|
|
|
|||
|
|
@ -228,9 +228,18 @@ export const razorDefaults = razorLanguageService.defaults;
|
|||
|
||||
// --- Registration to monaco editor ---
|
||||
|
||||
declare var AMD: any;
|
||||
declare var require: any;
|
||||
|
||||
function getMode(): Promise<typeof mode> {
|
||||
if (AMD) {
|
||||
return new Promise((resolve, reject) => {
|
||||
require(['vs/language/html/htmlMode'], resolve, reject);
|
||||
});
|
||||
} else {
|
||||
return import('./htmlMode');
|
||||
}
|
||||
}
|
||||
|
||||
export interface LanguageServiceRegistration extends IDisposable {
|
||||
readonly defaults: LanguageServiceDefaults;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue