bundle.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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');
  25. bundleOne('tsWorker');
  26. function bundleOne(moduleId, exclude) {
  27. requirejs.optimize(
  28. {
  29. baseUrl: 'release/dev/',
  30. name: 'vs/language/typescript/' + moduleId,
  31. out: 'release/min/' + moduleId + '.js',
  32. exclude: exclude,
  33. paths: {
  34. 'vs/language/typescript': REPO_ROOT + '/release/dev'
  35. },
  36. optimize: 'none'
  37. },
  38. async function (buildResponse) {
  39. const filePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
  40. const fileContents = fs.readFileSync(filePath).toString();
  41. console.log();
  42. console.log(`Minifying ${filePath}...`);
  43. const result = await terser.minify(fileContents);
  44. console.log(`Done minifying ${filePath}.`);
  45. fs.writeFileSync(filePath, BUNDLED_FILE_HEADER + result.code);
  46. }
  47. );
  48. }