bundle.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 UglifyJS = require('uglify-js');
  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. updateImports('monaco.contribution');
  27. function bundleOne(moduleId, exclude) {
  28. requirejs.optimize({
  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. 'vs/basic-languages': REPO_ROOT + '/node_modules/monaco-languages/release/dev'
  36. },
  37. optimize: 'none'
  38. }, 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 = UglifyJS.minify(fileContents, {
  44. output: {
  45. comments: 'some'
  46. }
  47. });
  48. console.log(`Done.`);
  49. fs.writeFileSync(filePath, BUNDLED_FILE_HEADER + result.code);
  50. })
  51. }
  52. function updateImports(moduleId) {
  53. const filePath = path.join(REPO_ROOT, 'release/esm/' + moduleId + '.js');
  54. let fileContents = fs.readFileSync(filePath).toString();
  55. fileContents = fileContents.replace(/vs\/basic-languages\//g, "../../basic-languages/");
  56. fs.writeFileSync(filePath, fileContents);
  57. }