diff --git a/.gitignore b/.gitignore index 6cacbd1b..549e2a90 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ test/transform_export/out.js test/exports_basics/out.js test/circular/export/ test/serviceworker/service-worker.js +!test/dev_bundles_minify/node_modules diff --git a/lib/bundle/add_npm_packages_node.js b/lib/bundle/add_npm_packages_node.js index f9b0a6fd..b29b5d46 100644 --- a/lib/bundle/add_npm_packages_node.js +++ b/lib/bundle/add_npm_packages_node.js @@ -1,3 +1,4 @@ +var prettier = require("prettier"); /** * Adds node to bundle to preload npm packages for dev bundles @@ -6,11 +7,8 @@ * @param {{}} npmContext The context containing the npm packages loaded */ module.exports = function(bundle, npmContext) { - var unshift = [].unshift; - - unshift.apply(bundle.nodes, [ - makeAddNpmPackagesNode(npmContext) - ]); + var push = [].push; + push.apply(bundle.nodes, [makeAddNpmPackagesNode(npmContext)]); }; function makeAddNpmPackagesNode(npmContext) { @@ -23,11 +21,12 @@ function makeAddNpmPackagesNode(npmContext) { metadata: { format: "global" }, - source: [ - "if (steal && typeof steal.addNpmPackages === 'function') {", - "steal.addNpmPackages(" + JSON.stringify(packages) + ");", - "}" - ].join(" ") + source: prettier.format( + `if (steal && typeof steal.addNpmPackages === "function") { + steal.addNpmPackages(${JSON.stringify(packages)}); + }`, + { tabWidth: 4 } + ) } }; } diff --git a/test/dev_bundle_build_test.js b/test/dev_bundle_build_test.js index 041dafc2..82444510 100644 --- a/test/dev_bundle_build_test.js +++ b/test/dev_bundle_build_test.js @@ -344,4 +344,38 @@ describe("dev bundle build", function() { return rmdir(devBundlePath); }); }); + + it("minified dev bundles work", function(done) { + var dir = path.join(__dirname, "dev_bundles_minify"); + var devBundlePath = path.join(dir, "dev-bundle.js"); + + var config = { + config: path.join(dir, "package.json!npm") + }; + + var options = assign({}, baseOptions, { + minify: true, + filter: "node_modules/**/*" // only bundle npm deps + }); + + var clean = function(err) { + rmdir(devBundlePath).then(function() { + done(err); + }); + }; + devBundleBuild(config, options) + .then(function() { + var exists = fs.existsSync(devBundlePath); + assert(exists, "dev bundle should be created"); + }) + .then(function() { + return open("test/dev_bundles_minify/dev.html"); + }) + .then(function(p) { + p.close(); + p.browser.assert.element("h1"); + }) + .then(clean) + .catch(clean); + }); }); diff --git a/test/dev_bundles_minify/dev.html b/test/dev_bundles_minify/dev.html new file mode 100644 index 00000000..78908e2c --- /dev/null +++ b/test/dev_bundles_minify/dev.html @@ -0,0 +1,16 @@ + + +
+ + + +