Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile sass in beforeBuild instead of as separate gulp task #9

Merged
merged 3 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 27 additions & 18 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const { DateTime } = require("luxon");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const fs = require("fs");
const fs = require("fs-extra");
const path = require("path");
const getTagList = require("./_11ty/getTagList");
const MarkdownIt = require("markdown-it");
const lodash = require("lodash");
const slugify = require("slugify");
const sass = require("sass");
const postcss = require("postcss");
const autoprefixer = require("autoprefixer");

/**
* Get all unique key values from a collection
Expand Down Expand Up @@ -143,25 +146,31 @@ module.exports = function (eleventyConfig) {
});

eleventyConfig.addFilter("include", require("./filters/include.js"));
/*
eleventyConfig.setBrowserSyncConfig({
callbacks: {
ready: function(err, bs) {
const content_404 = fs.readFileSync('./_site/404.html');
bs.addMiddleware('*', (req, res) => {
// Provides the 404 content without redirect.
res.write(content_404);
res.end();

// compile sass and optimize it https://www.d-hagemeier.com/en/articles/sass-compile-11ty/
eleventyConfig.on("beforeBuild", () => {
// Compile Sass
let result = sass.renderSync({
file: "_sass/main.scss",
sourceMap: false,
outputStyle: "compressed",
});
console.log("SCSS compiled");

// Optimize and write file with PostCSS
let css = result.css.toString();
postcss([autoprefixer])
.process(css, { from: "main.css", to: "css/main.css" })
.then((result) => {
fs.outputFile("_site/css/main.css", result.css, (err) => {
if (err) throw err;
console.log("CSS optimized");
});
},
},
ghostMode: {
clicks: false,
forms: false,
scroll: false,
},
});
});
*/

// trigger a rebuild if sass changes
eleventyConfig.addWatchTarget("_sass/");

return {
templateFormats: ["md", "njk", "html", "liquid", "hbs"],
Expand Down
1 change: 0 additions & 1 deletion css/main.css

This file was deleted.

13 changes: 0 additions & 13 deletions gulpfile.js

This file was deleted.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "5.0.0",
"description": "A starter repository for a blog web site using the Eleventy static site generator.",
"scripts": {
"build": "npx gulp & npx eleventy",
"build": "npx eleventy",
"start": "npx eleventy --serve",
"debug": "DEBUG=* npx eleventy"
},
Expand All @@ -19,8 +19,6 @@
"url": "https://github.com/clottman/cassey-on-eleventy/issues"
},
"dependencies": {
"gulp": "^4.0.2",
"gulp-sass": "^4.0.2",
"lodash": "^4.17.20",
"nunjucks": "^3.2.2",
"slugify": "^1.4.6",
Expand All @@ -30,8 +28,12 @@
"@11ty/eleventy": "^0.11.1",
"@11ty/eleventy-plugin-rss": "^1.0.9",
"@11ty/eleventy-plugin-syntaxhighlight": "^3.0.4",
"autoprefixer": "^10.0.2",
"fs-extra": "^9.0.1",
"luxon": "^1.25.0",
"markdown-it": "^12.0.2",
"markdown-it-anchor": "^6.0.0"
"markdown-it-anchor": "^6.0.0",
"postcss": "^8.1.8",
"sass": "^1.29.0"
}
}