Skip to content

Commit

Permalink
support less
Browse files Browse the repository at this point in the history
  • Loading branch information
SmokingRabbit committed Mar 7, 2020
1 parent 2ca19a9 commit 38a8a5a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"html-minifier": "^4.0.0",
"imagemin": "^7.0.1",
"json2yaml": "^1.1.0",
"less": "^3.11.1",
"node-sass": "^4.13.1",
"rcfile": "^1.0.3",
"spritesmith": "^3.4.0"
Expand All @@ -45,10 +46,12 @@
"@types/browser-sync": "^2.26.1",
"@types/html-minifier": "^3.5.3",
"@types/imagemin": "^7.0.0",
"@types/less": "^3.0.1",
"@types/node": "^13.7.0",
"@types/node-sass": "^4.11.0",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.18.0",
"eslint": "^6.8.0",
"eslint-plugin-chowa-standard": "latest",
"gulp": "^4.0.2",
"gulp-banner": "^0.1.3",
Expand Down
21 changes: 18 additions & 3 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as fs from 'fs';
import * as path from 'path';
import cwlog from 'chowa-log';
import * as utils from './utils';
import * as sassc from 'node-sass';
import * as sass from 'node-sass';
import * as less from 'less';
export type TypeDeclare = 'extend' | 'block' | 'include' | 'if' | 'each' | 'set' | 'var' | 'style' | 'script';

export interface Node {
Expand Down Expand Up @@ -421,8 +422,22 @@ class Template {
let css = fs.readFileSync(file).toString();
const { ext } = path.parse(file);

if (ext === '.scss' && css) {
css = sassc.renderSync({ data: css }).css.toString();
if (!css) {
return '';
}

if (ext === '.scss') {
css = sass.renderSync({ data: css }).css.toString();
}
else if (ext === '.less') {
less.render(css)
.then((output) => {
css = output.css;
})
.catch((reason) => {
css = '';
cwlog.error(reason);
});
}

return `<style type="text/css">\n${css.replace(/\.\.\/image/g, 'image')}\n</style>`;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es6",
"lib": ["es7"],
"lib": ["es7", "dom"],
"module": "commonjs",
"moduleResolution": "node",
"noResolve": false,
Expand Down

0 comments on commit 38a8a5a

Please sign in to comment.