1
0

bundle.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const requirejs = require('requirejs');
  2. const path = require('path');
  3. const fs = require('fs');
  4. const Terser = require('terser');
  5. const helpers = require('monaco-plugin-helpers');
  6. const REPO_ROOT = path.resolve(__dirname, '..');
  7. const sha1 = helpers.getGitVersion(REPO_ROOT);
  8. const semver = require('../package.json').version;
  9. const headerVersion = semver + '(' + sha1 + ')';
  10. const BUNDLED_FILE_HEADER = [
  11. '/*!-----------------------------------------------------------------------------',
  12. ' * Copyright (c) Microsoft Corporation. All rights reserved.',
  13. ' * monaco-json version: ' + headerVersion,
  14. ' * Released under the MIT license',
  15. ' * https://github.com/Microsoft/monaco-json/blob/master/LICENSE.md',
  16. ' *-----------------------------------------------------------------------------*/',
  17. ''
  18. ].join('\n');
  19. bundleOne('monaco.contribution');
  20. bundleOne('jsonMode', ['vs/language/json/monaco.contribution']);
  21. bundleOne('jsonWorker');
  22. function bundleOne(moduleId, exclude) {
  23. requirejs.optimize(
  24. {
  25. baseUrl: 'out/amd/',
  26. name: 'vs/language/json/' + moduleId,
  27. out: 'release/dev/' + moduleId + '.js',
  28. exclude: exclude,
  29. paths: {
  30. 'vs/language/json': REPO_ROOT + '/out/amd',
  31. 'vs/language/json/fillers/monaco-editor-core':
  32. REPO_ROOT + '/out/amd/fillers/monaco-editor-core-amd'
  33. },
  34. optimize: 'none',
  35. packages: [
  36. {
  37. name: 'vscode-json-languageservice',
  38. location: path.join(REPO_ROOT, 'node_modules/vscode-json-languageservice/lib/umd'),
  39. main: 'jsonLanguageService'
  40. },
  41. {
  42. name: 'vscode-languageserver-types',
  43. location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'),
  44. main: 'main'
  45. },
  46. {
  47. name: 'vscode-languageserver-textdocument',
  48. location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-textdocument/lib/umd'),
  49. main: 'main'
  50. },
  51. {
  52. name: 'jsonc-parser',
  53. location: path.join(REPO_ROOT, 'node_modules/jsonc-parser/lib/umd'),
  54. main: 'main'
  55. },
  56. {
  57. name: 'vscode-uri',
  58. location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
  59. main: 'index'
  60. },
  61. {
  62. name: 'minimatch',
  63. location: path.join(REPO_ROOT, 'node_modules/minimatch'),
  64. main: 'minimatch'
  65. },
  66. {
  67. name: 'vscode-nls',
  68. location: path.join(REPO_ROOT, '/out/amd/fillers'),
  69. main: 'vscode-nls'
  70. }
  71. ]
  72. },
  73. async function (buildResponse) {
  74. const devFilePath = path.join(REPO_ROOT, 'release/dev/' + moduleId + '.js');
  75. const minFilePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
  76. const fileContents = fs.readFileSync(devFilePath).toString();
  77. console.log(`Minifying ${devFilePath}...`);
  78. const result = await Terser.minify(fileContents, {
  79. output: {
  80. comments: 'some'
  81. }
  82. });
  83. console.log(`Done minifying ${devFilePath}.`);
  84. try {
  85. fs.mkdirSync(path.join(REPO_ROOT, 'release/min'));
  86. } catch (err) {}
  87. fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
  88. }
  89. );
  90. }