-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
58 lines (50 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const path = require("path");
const pkg = require("./package.json");
module.exports = (eleventyConfig, options = {}) => {
const {
sass,
outputPath = "css",
outputStyle = "expanded",
includePaths = ["node_modules"],
sourceMap = false,
cache = false,
} = options;
const outputFileExtension = "css";
try {
eleventyConfig.versionCheck(pkg["11ty"].compatibility);
} catch (e) {
console.log(
`WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}`
);
}
eleventyConfig.addTemplateFormats("scss");
// Creates the extension for use
eleventyConfig.addExtension("scss", {
outputFileExtension,
compileOptions: {
cache,
permalink: (_inputContent, inputPath) => (_data) => {
let parsed = path.parse(inputPath);
if (parsed.name.startsWith("_")) return; // Ignore partials
if (!outputPath) return; // default to inputPath
return `/${outputPath}/${parsed.name}.${outputFileExtension}`;
},
},
getData: async () => ({ eleventyExcludeFromCollections: true }),
compile: (inputContent, inputPath) => {
let parsed = path.parse(inputPath);
if (parsed.name.startsWith("_")) return; // Ignore partials
const loadPaths = [
parsed.dir || ".",
eleventyConfig.dir.includes || "_includes",
...includePaths,
];
let result = sass.compileString(inputContent, {
style: outputStyle,
sourceMap,
loadPaths,
});
return async (_data) => result.css;
},
});
};