Skip to content

Commit

Permalink
fix: now properly emits HTML files
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers committed Oct 17, 2020
1 parent e2ea05d commit f01c1dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
10 changes: 9 additions & 1 deletion __tests__/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ Build("Should rewrite to a hashed script for index.html", () => {
});
});

Build("Should inject an 'application.css' stylesheet", () => {});
Build("Should create HTML files", () => {
const HTMLFiles = ["index.html", "html/index.html"];

HTMLFiles.forEach((file) => {
file = path.resolve(buildDir, file);

assert.is(fs.existsSync(file), true);
});
});

Build.run();
2 changes: 0 additions & 2 deletions __tests__/emitHtmlFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ EmitHtmlFiles("Rewrite relative import to absolute", () => {
const firstScript = domDoc.querySelector("script");
firstScript.src = "entrypoints/application.js";

console.log("HI");
const newDom = rewriteScripts({
dom,
manifest: mockManifest,
baseUrl: "/",
});

console.log("HI");
const newScript = newDom.window.document.querySelector("script");
assert.is(newScript.src, mockManifest.entrypoints.application.js);
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/examples/example_dir/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4694,7 +4694,7 @@ snapdragon@^0.8.1:
use "^3.1.0"

"snowpack-plugin-rollup-bundle@file:../../../pkg":
version "0.2.3"
version "0.3.0"
dependencies:
"@rollup/plugin-commonjs" "^15.1.0"
"@rollup/plugin-node-resolve" "^9.0.0"
Expand Down
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ async function rollupBuild({

// Add assets to manifest, use path.relative to fix minor issues
glob.sync(`${TMP_BUILD_DIRECTORY}/**/*.*`).forEach((fileName) => {
console.log(fileName);
fileName = path.relative(TMP_BUILD_DIRECTORY, fileName);
const chunkOrAsset = { fileName, map: null };
addToManifest({
Expand All @@ -84,10 +85,18 @@ async function rollupBuild({
manifestJSON
);

// HTML files will not be pulled in by rollup, its up to us
// to manually pull them in.
if (pluginOptions.emitHtml === true) {
glob.sync(buildDirectory + "**/*.html").forEach((file) => {
glob.sync(buildDirectory + "/**/*.html").forEach((file) => {
let destFile = path.relative(buildDirectory, file);
destFile = path.join(TMP_BUILD_DIRECTORY, destFile);
destFile = path.resolve(TMP_BUILD_DIRECTORY, destFile);
const destDir = path.parse(destFile).dir;

if (!fs.existsSync(destDir)) {
fs.mkdirSync(destDir, { recursive: true });
}

emitHtmlFiles({ file, manifest, destFile, baseUrl });
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path";

// plugins
import resolve from "@rollup/plugin-node-resolve";
import commonjs from '@rollup/plugin-commonjs';
import commonjs from "@rollup/plugin-commonjs";
import styles from "rollup-plugin-styles";
import { terser } from "rollup-plugin-terser";
import url from "@rollup/plugin-url";
Expand All @@ -26,7 +26,7 @@ export function defaultInputOptions({ buildDirectory, tmpDir }) {
limit: 0, // extract all files
fileName: "[dirname]/[name]-[hash][extname]",
}),
commonjs()
commonjs(),
],
};
}
Expand Down

0 comments on commit f01c1dd

Please sign in to comment.