mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 16:15:41 +01:00
Use esbuild also for AMD variant
This commit is contained in:
parent
63e425ffe2
commit
829ee45850
5 changed files with 85 additions and 100 deletions
|
|
@ -81,8 +81,8 @@ exports.removeDir = removeDir;
|
||||||
*/
|
*/
|
||||||
function tsc(_projectPath) {
|
function tsc(_projectPath) {
|
||||||
const projectPath = path.join(REPO_ROOT, _projectPath);
|
const projectPath = path.join(REPO_ROOT, _projectPath);
|
||||||
|
console.log(`Launching compiler at ${_projectPath}...`);
|
||||||
cp.spawnSync(process.execPath, [path.join(__dirname, '../node_modules/typescript/lib/tsc.js'), '-p', projectPath], { stdio: 'inherit', stderr: 'inherit' });
|
cp.spawnSync(process.execPath, [path.join(__dirname, '../node_modules/typescript/lib/tsc.js'), '-p', projectPath], { stdio: 'inherit', stderr: 'inherit' });
|
||||||
|
|
||||||
console.log(`Compiled ${_projectPath}`);
|
console.log(`Compiled ${_projectPath}`);
|
||||||
}
|
}
|
||||||
exports.tsc = tsc;
|
exports.tsc = tsc;
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,17 @@ removeDir(`monaco-css/out`);
|
||||||
|
|
||||||
tsc(`monaco-css/src/tsconfig.json`);
|
tsc(`monaco-css/src/tsconfig.json`);
|
||||||
|
|
||||||
dts(`monaco-css/out/amd/monaco.contribution.d.ts`, `monaco-css/monaco.d.ts`, 'monaco.languages.css');
|
dts(
|
||||||
|
`monaco-css/out/amd/monaco.contribution.d.ts`,
|
||||||
|
`monaco-css/monaco.d.ts`,
|
||||||
|
'monaco.languages.css'
|
||||||
|
);
|
||||||
|
|
||||||
esbuild.build({
|
/**
|
||||||
entryPoints: ['src/cssMode.ts', 'src/css.worker.ts', 'src/monaco.contribution.ts'],
|
* @param {import('esbuild').BuildOptions} options
|
||||||
bundle: true,
|
*/
|
||||||
target: 'esnext',
|
function build(options) {
|
||||||
format: 'esm',
|
esbuild.build(options).then((result) => {
|
||||||
external: ['monaco-editor-core', '*/cssMode'],
|
|
||||||
outdir: 'release/esm/',
|
|
||||||
plugins: [
|
|
||||||
alias({
|
|
||||||
'vscode-nls': path.join(__dirname, '../src/fillers/vscode-nls.ts'),
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}).then((result) => {
|
|
||||||
if (result.errors.length > 0) {
|
if (result.errors.length > 0) {
|
||||||
console.error(result.errors);
|
console.error(result.errors);
|
||||||
}
|
}
|
||||||
|
|
@ -36,5 +32,70 @@ esbuild.build({
|
||||||
console.error(result.warnings);
|
console.error(result.warnings);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
cp.spawnSync(process.execPath, [path.join(__dirname, './bundle.js')], { stdio: 'inherit', stderr: 'inherit' });
|
build({
|
||||||
|
entryPoints: ['src/monaco.contribution.ts', 'src/cssMode.ts', 'src/css.worker.ts'],
|
||||||
|
bundle: true,
|
||||||
|
target: 'esnext',
|
||||||
|
format: 'esm',
|
||||||
|
define: {
|
||||||
|
AMD: false
|
||||||
|
},
|
||||||
|
external: ['monaco-editor-core', '*/cssMode'],
|
||||||
|
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: ['*/cssMode'],
|
||||||
|
globalName: 'moduleExports',
|
||||||
|
banner: {
|
||||||
|
js: banner
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
js: 'return moduleExports;\n});'
|
||||||
|
},
|
||||||
|
outdir: `release/${type}/`,
|
||||||
|
plugins: [
|
||||||
|
alias({
|
||||||
|
'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/css/monaco.contribution",["vs/editor/editor.api"],()=>{');
|
||||||
|
buildAMD('src/cssMode.ts', 'define("vs/language/css/cssMode",["vs/editor/editor.api"],()=>{');
|
||||||
|
buildAMD('src/cssWorker.ts', 'define("vs/language/css/cssWorker",[],()=>{');
|
||||||
|
|
|
||||||
|
|
@ -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('cssMode', ['vs/language/css/monaco.contribution']);
|
|
||||||
bundleOne('cssWorker');
|
|
||||||
|
|
||||||
function bundleOne(moduleId, exclude) {
|
|
||||||
requirejs.optimize(
|
|
||||||
{
|
|
||||||
baseUrl: 'out/amd/',
|
|
||||||
name: 'vs/language/css/' + moduleId,
|
|
||||||
out: 'release/dev/' + moduleId + '.js',
|
|
||||||
exclude: exclude,
|
|
||||||
paths: {
|
|
||||||
'vs/language/css': REPO_ROOT + '/monaco-css/out/amd',
|
|
||||||
'vs/language/css/fillers/monaco-editor-core':
|
|
||||||
REPO_ROOT + '/monaco-css/out/amd/fillers/monaco-editor-core-amd'
|
|
||||||
},
|
|
||||||
optimize: 'none',
|
|
||||||
packages: [
|
|
||||||
{
|
|
||||||
name: 'vscode-css-languageservice',
|
|
||||||
location: path.join(REPO_ROOT, 'node_modules/vscode-css-languageservice/lib/umd'),
|
|
||||||
main: 'cssLanguageService'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
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-css/out/amd/fillers'),
|
|
||||||
main: 'vscode-nls'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
async function (buildResponse) {
|
|
||||||
const devFilePath = path.join(REPO_ROOT, 'monaco-css/release/dev/' + moduleId + '.js');
|
|
||||||
const minFilePath = path.join(REPO_ROOT, 'monaco-css/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-css/release/min'));
|
|
||||||
} catch (err) {}
|
|
||||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -5,8 +5,4 @@
|
||||||
|
|
||||||
// Resolves with the global monaco API
|
// Resolves with the global monaco API
|
||||||
|
|
||||||
declare var define;
|
export = (<any>self).monaco;
|
||||||
|
|
||||||
define([], function () {
|
|
||||||
return (<any>self).monaco;
|
|
||||||
});
|
|
||||||
|
|
|
||||||
|
|
@ -218,9 +218,16 @@ export const lessDefaults: LanguageServiceDefaults = new LanguageServiceDefaults
|
||||||
|
|
||||||
// --- Registration to monaco editor ---
|
// --- Registration to monaco editor ---
|
||||||
|
|
||||||
|
declare var AMD: any;
|
||||||
|
declare var require: any;
|
||||||
|
|
||||||
function getMode(): Promise<typeof mode> {
|
function getMode(): Promise<typeof mode> {
|
||||||
|
if (AMD) {
|
||||||
|
return new Promise((resolve, reject) => { require(['vs/language/css/cssMode'], resolve, reject); });
|
||||||
|
} else {
|
||||||
return import('./cssMode');
|
return import('./cssMode');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
languages.onLanguage('less', () => {
|
languages.onLanguage('less', () => {
|
||||||
getMode().then((mode) => mode.setupMode(lessDefaults));
|
getMode().then((mode) => mode.setupMode(lessDefaults));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue