Skip to content

Commit

Permalink
Merge pull request #21 from byr-gdp/fix
Browse files Browse the repository at this point in the history
fix: build failed when output directory not exists
  • Loading branch information
xiaofuzi authored Oct 31, 2018
2 parents 81cd346 + d2c8db0 commit 3468e83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"babel-runtime": "^6.26.0",
"fs-extra": "^0.30.0",
"less": "^2.7.1",
"mkdirp": "^0.5.1",
"rollup": "^0.34.7",
"rollup-pluginutils": "^1.5.1"
},
Expand Down
16 changes: 15 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ import { dirname } from 'path';
import less from 'less';
import { createFilter } from 'rollup-pluginutils';
import { insertStyle } from './style.js';
import mkdirp from 'mkdirp';

/**
* 根据路径写入文件,文件夹不存在则创建
* @param {String} path 路径
* @param {String} contents 待写入文件内容
* @param {Function} cb 回调函数
*/
const writeFile = (path, contents, cb) => {
mkdirp(dirname(path), function (err) {
if (err && typeof cb === 'function') return cb(err);

fs.writeFile(path, contents, cb);
});
}

let renderSync = (code, option) => {
return less.render(code, option)
Expand Down Expand Up @@ -51,7 +65,7 @@ export default function plugin (options = {}) {
//clean the output file
fs.removeSync(options.output);
}
fs.appendFileSync(options.output, css);
writeFile(options.output, css);
}

let exportCode = '';
Expand Down

0 comments on commit 3468e83

Please sign in to comment.