From ef731a495c5966398345f15875704100bb34b3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Mon, 24 Jan 2022 17:11:14 +0100 Subject: [PATCH] feat: removed watch command, replaced it by eleventyConfig --- .eleventy.js | 104 +++++++++++++++++++++++++++++---------------------- package.json | 8 +--- 2 files changed, 61 insertions(+), 51 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 587d4ea..149ac48 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,57 +1,71 @@ -const pluginNavigation = require('@11ty/eleventy-navigation') -const markdownItAttrs = require('markdown-it-attrs') -const markdownIt = require('markdown-it') -const htmlmin = require('html-minifier') +const pluginNavigation = require("@11ty/eleventy-navigation"); +const markdownItAttrs = require("markdown-it-attrs"); +const markdownIt = require("markdown-it"); +const htmlmin = require("html-minifier"); const yaml = require("js-yaml"); -const options = { +const sass = require("sass"); +const fs = require("fs"); +const markdownLib = markdownIt({ html: true, breaks: true, - linkify: true -} -const markdownLib = markdownIt(options).use(markdownItAttrs) - + linkify: true, +}).use(markdownItAttrs); module.exports = function (eleventyConfig) { - eleventyConfig.addDataExtension("yml", contents => yaml.load(contents)); - eleventyConfig.addGlobalData('username', 'Laureηt') - eleventyConfig.addWatchTarget('./src/scss/') - eleventyConfig.setLibrary('md', markdownLib) - eleventyConfig.addPlugin(pluginNavigation) + eleventyConfig.addDataExtension("yml", (contents) => yaml.load(contents)); + eleventyConfig.addGlobalData("username", "Laureηt"); + eleventyConfig.addWatchTarget("./src/scss/"); + eleventyConfig.setLibrary("md", markdownLib); + eleventyConfig.addPlugin(pluginNavigation); + eleventyConfig.setUseGitIgnore(false); eleventyConfig.addPassthroughCopy({ - 'assets/': './' - }) + "assets/": "./", + }); - if (process.env.ELEVENTY_ENV === 'prod') { - eleventyConfig.addTransform('htmlmin', function (content, outputPath) { - // Eleventy 1.0+: use this.inputPath and this.outputPath instead - if (outputPath && outputPath.endsWith('.html')) { - const minified = htmlmin.minify(content, { - collapseWhitespace: true, - useShortDoctype: true, - removeComments: true, - minifyCSS: true, - minifyJS: true - }) - return minified - } else { - return content - } - }) - } + eleventyConfig.on("eleventy.before", () => { + let files = fs.readdirSync("./src/scss/"); + files.forEach((file) => { + // Compile SASS + let result = sass.compile("./src/scss/".concat(file), { + style: "compressed", + sourceMap: false, + }); + console.log(`[SCSS] ${file} compiled`); + }); + }); - eleventyConfig.addShortcode('year', () => { - const year = new Date().getFullYear() - return year.toString() - }) + eleventyConfig.addTransform("htmlmin", function (content, outputPath) { + if ( + process.env.NODE_ENV === "production" && + outputPath && + outputPath.endsWith(".html") + ) { + const minified = htmlmin.minify(content, { + collapseWhitespace: true, + useShortDoctype: true, + removeComments: true, + minifyCSS: true, + minifyJS: true, + }); + return minified; + } else { + return content; + } + }); + + eleventyConfig.addShortcode("year", () => { + const year = new Date().getFullYear(); + return year.toString(); + }); return { - markdownTemplateEngine: 'njk', + markdownTemplateEngine: "njk", passthroughFileCopy: true, dir: { - includes: '_includes', - output: '_site', - data: '_data', - input: 'src' - } - } -} + includes: "_includes", + output: "_site", + data: "_data", + input: "src", + }, + }; +}; diff --git a/package.json b/package.json index bb47210..9a4e010 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,8 @@ "author": "Laureηt ", "license": "MIT", "scripts": { - "watch:sass": "sass --no-source-map --watch src/scss:src/_includes/css", - "watch:eleventy": "eleventy --serve", - "build:sass": "sass --no-source-map --style compressed src/scss:src/_includes/css", - "build:eleventy": "ELEVENTY_ENV=prod eleventy", - "start": "npm-run-all build:sass --parallel watch:*", - "build": "npm-run-all build:sass build:eleventy" + "dev": "eleventy --serve", + "build": "NODE_ENV=production eleventy" }, "dependencies": { "@11ty/eleventy": "^1.0.0",