UNPKG

761 BJavaScriptView Raw
1var prettier = require("prettier");
2
3/**
4 * Adds node to bundle to preload npm packages for dev bundles
5 *
6 * @param {{}} bundle The bundle to be mutated
7 * @param {{}} npmContext The context containing the npm packages loaded
8 */
9module.exports = function(bundle, npmContext) {
10 var push = [].push;
11 push.apply(bundle.nodes, [makeAddNpmPackagesNode(npmContext)]);
12};
13
14function makeAddNpmPackagesNode(npmContext) {
15 var packages = npmContext.packages || [];
16
17 return {
18 deps: [],
19 load: {
20 name: "[steal-add-npm-packages]",
21 metadata: {
22 format: "global"
23 },
24 source: prettier.format(
25 `if (steal && typeof steal.addNpmPackages === "function") {
26 steal.addNpmPackages(${JSON.stringify(packages)});
27 }`,
28 { tabWidth: 4 }
29 )
30 }
31 };
32}