bundle.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. const requirejs = require('requirejs');
  6. const path = require('path');
  7. const fs = require('fs');
  8. const terser = require('terser');
  9. const helpers = require('monaco-plugin-helpers');
  10. const REPO_ROOT = path.resolve(__dirname, '..', '..');
  11. const sha1 = helpers.getGitVersion(REPO_ROOT);
  12. const semver = require('../../package.json').version;
  13. const headerVersion = semver + '(' + sha1 + ')';
  14. const BUNDLED_FILE_HEADER = [
  15. '/*!-----------------------------------------------------------------------------',
  16. ' * Copyright (c) Microsoft Corporation. All rights reserved.',
  17. ' * monaco-typescript version: ' + headerVersion,
  18. ' * Released under the MIT license',
  19. ' * https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md',
  20. ' *-----------------------------------------------------------------------------*/',
  21. ''
  22. ].join('\n');
  23. bundleOne('monaco.contribution');
  24. bundleOne('tsMode', ['vs/language/typescript/monaco.contribution']);
  25. bundleOne('tsWorker');
  26. function bundleOne(moduleId, exclude) {
  27. requirejs.optimize(
  28. {
  29. baseUrl: 'out/amd/',
  30. name: 'vs/language/typescript/' + moduleId,
  31. out: 'release/dev/' + moduleId + '.js',
  32. exclude: exclude,
  33. paths: {
  34. 'vs/language/typescript': REPO_ROOT + '/monaco-typescript/out/amd',
  35. 'vs/language/typescript/fillers/monaco-editor-core':
  36. REPO_ROOT + '/monaco-typescript/out/amd/fillers/monaco-editor-core-amd'
  37. },
  38. optimize: 'none'
  39. },
  40. async function (buildResponse) {
  41. const devFilePath = path.join(REPO_ROOT, 'monaco-typescript/release/dev/' + moduleId + '.js');
  42. const minFilePath = path.join(REPO_ROOT, 'monaco-typescript/release/min/' + moduleId + '.js');
  43. const fileContents = fs.readFileSync(devFilePath).toString();
  44. console.log();
  45. console.log(`Minifying ${devFilePath}...`);
  46. const result = await terser.minify(fileContents, {
  47. output: {
  48. comments: 'some'
  49. }
  50. });
  51. console.log(`Done minifying ${devFilePath}.`);
  52. try {
  53. fs.mkdirSync(path.join(REPO_ROOT, 'monaco-typescript/release/min'));
  54. } catch (err) {}
  55. fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
  56. }
  57. );
  58. }