mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
* Adding/removing extra libs does not trigger a full worker refresh * Manual control over when the extra libs are sent to the worker * Adding a new lib with the same name replaces it inplace Also included, the capability to define custom languages
66 lines
No EOL
2.4 KiB
JavaScript
66 lines
No EOL
2.4 KiB
JavaScript
/*---------------------------------------------------------------------------------------------
|
|
* 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 UglifyJS = require('uglify-js');
|
|
const helpers = require('monaco-plugin-helpers');
|
|
|
|
const REPO_ROOT = path.resolve(__dirname, '..');
|
|
|
|
const sha1 = helpers.getGitVersion(REPO_ROOT);
|
|
const semver = require('../package.json').version;
|
|
const headerVersion = semver + '(' + sha1 + ')';
|
|
|
|
const BUNDLED_FILE_HEADER = [
|
|
'/*!-----------------------------------------------------------------------------',
|
|
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
|
' * monaco-typescript version: ' + headerVersion,
|
|
' * Released under the MIT license',
|
|
' * https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md',
|
|
' *-----------------------------------------------------------------------------*/',
|
|
''
|
|
].join('\n');
|
|
|
|
bundleOne('monaco.contribution');
|
|
bundleOne('tsMode');
|
|
bundleOne('tsWorker');
|
|
|
|
updateImports('monaco.contribution');
|
|
|
|
function bundleOne(moduleId, exclude) {
|
|
requirejs.optimize({
|
|
baseUrl: 'release/dev/',
|
|
name: 'vs/language/typescript/' + moduleId,
|
|
out: 'release/min/' + moduleId + '.js',
|
|
exclude: exclude,
|
|
paths: {
|
|
'vs/language/typescript': REPO_ROOT + '/release/dev',
|
|
'vs/basic-languages': REPO_ROOT + '/node_modules/monaco-languages/release/dev'
|
|
},
|
|
optimize: 'none'
|
|
}, function(buildResponse) {
|
|
const filePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
|
|
const fileContents = fs.readFileSync(filePath).toString();
|
|
console.log();
|
|
console.log(`Minifying ${filePath}...`);
|
|
const result = UglifyJS.minify(fileContents, {
|
|
output: {
|
|
comments: 'some'
|
|
}
|
|
});
|
|
console.log(`Done.`);
|
|
fs.writeFileSync(filePath, BUNDLED_FILE_HEADER + result.code);
|
|
})
|
|
}
|
|
|
|
function updateImports(moduleId) {
|
|
console.log(`ESM: updating relative imports paths for ${moduleId}...`);
|
|
const filePath = path.join(REPO_ROOT, 'release/esm/' + moduleId + '.js');
|
|
var fileContents = fs.readFileSync(filePath).toString();
|
|
fileContents = fileContents.replace(/vs\/basic-languages\//g, "../../basic-languages/");
|
|
fs.writeFileSync(filePath, fileContents);
|
|
} |