Skip to content

Commit

Permalink
Remove Browsersync for Eleventy v2.x compatibility (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkvach committed Jan 18, 2024
1 parent f329204 commit e72d0c1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 35 deletions.
15 changes: 0 additions & 15 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,6 @@ module.exports = function (eleventyConfig) {
});
eleventyConfig.setLibrary("md", markdownLibrary);

// Browsersync Overrides
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function (err, browserSync) {
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.write(fs.readFileSync("_site/404.html"));
res.end();
});
},
},
ui: false,
ghostMode: false,
});

// After the build touch any file in the test directory to do a test run.
eleventyConfig.on("afterBuild", async () => {
const files = await readdir("test");
Expand Down
20 changes: 0 additions & 20 deletions _11ty/apply-csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,13 @@

const { JSDOM } = require("jsdom");
const cspHashGen = require("csp-hash-generator");
const syncPackage = require("browser-sync/package.json");

/**
* Substitute the magic `HASHES` string in the CSP with the actual values of the
* loaded JS files.
* The ACTUAL CSP is configured in `_data/csp.js`.
*/

// Allow the auto-reload script in local dev. Would be good to get rid of this magic
// string which would break on ungrades of 11ty.
const AUTO_RELOAD_SCRIPTS = [
quote(
cspHashGen(
"//<![CDATA[\n document.write(\"<script async src='/browser-sync/browser-sync-client.js?v=" +
syncPackage.version +
'\'><\\/script>".replace("HOST", location.hostname));\n//]]>'
)
),
];

function quote(str) {
return `'${str}'`;
}
Expand All @@ -59,9 +46,6 @@ const addCspHash = async (rawContent, outputPath) => {
element.setAttribute("csp-hash", hash);
return quote(hash);
});
if (isDevelopmentMode()) {
hashes.push.apply(hashes, AUTO_RELOAD_SCRIPTS);
}

const csp = dom.window.document.querySelector(
"meta[http-equiv='Content-Security-Policy']"
Expand Down Expand Up @@ -103,7 +87,3 @@ module.exports = {
eleventyConfig.addTransform("csp", addCspHash);
},
};

function isDevelopmentMode() {
return /serve|dev/.test(process.argv.join());
}

0 comments on commit e72d0c1

Please sign in to comment.