]> git.proxmox.com Git - mirror_novnc.git/blob - utils/use_require_helpers.js
Vendor in an IE11 polyfill for Promises
[mirror_novnc.git] / utils / use_require_helpers.js
1 // writes helpers require for vnc.html (they should output app.js)
2 var fs = require('fs');
3 var fse = require('fs-extra');
4 var path = require('path');
5
6 module.exports = {
7 'amd': {
8 appWriter: (base_out_path, out_path) => {
9 // setup for requirejs
10 fs.writeFile(out_path, 'requirejs(["app/ui"], function (ui) {});', (err) => { if (err) throw err; });
11 console.log(`Please place RequireJS in ${path.join(base_out_path, 'require.js')}`);
12 return `<script src="require.js" data-main="${path.relative(base_out_path, out_path)}"></script>`;
13 },
14 noCopyOverride: () => {},
15 },
16 'commonjs': {
17 optionsOverride: (opts) => {
18 // CommonJS supports properly shifting the default export to work as normal
19 opts.plugins.unshift("add-module-exports");
20 },
21 appWriter: (base_out_path, out_path) => {
22 var browserify = require('browserify');
23 var b = browserify(path.join(base_out_path, 'app/ui.js'), {});
24 b.bundle().pipe(fs.createWriteStream(out_path));
25 return `<script src="${path.relative(base_out_path, out_path)}"></script>`;
26 },
27 noCopyOverride: () => {},
28 },
29 'systemjs': {
30 appWriter: (base_out_path, out_path) => {
31 fs.writeFile(out_path, 'SystemJS.import("./app/ui.js");', (err) => { if (err) throw err; });
32 console.log(`Please place SystemJS in ${path.join(base_out_path, 'system-production.js')}`);
33 return `<script src="vendor/promise.js"></script>
34 <script src="system-production.js"></script>\n<script src="${path.relative(base_out_path, out_path)}"></script>`;
35 },
36 noCopyOverride: (paths, no_copy_files) => {
37 no_copy_files.delete(path.join(paths.vendor, 'promise.js'));
38 },
39 },
40 'umd': {
41 optionsOverride: (opts) => {
42 // umd supports properly shifting the default export to work as normal
43 opts.plugins.unshift("add-module-exports");
44 },
45 },
46 }