add woff2 support
use es6 module
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
/**
|
||||
* @file 单独编译css文件
|
||||
* @author mengke01(kekee000@gmail.com)
|
||||
*/
|
||||
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var less = require('less');
|
||||
var BASE_DIR = process.cwd();
|
||||
|
||||
// 默认的文件列表
|
||||
var DEFAULT_FILES = [
|
||||
'css/main.less',
|
||||
'css/preview.less'
|
||||
];
|
||||
|
||||
|
||||
main(process.argv.slice(2));
|
||||
|
||||
function main(fileList) {
|
||||
var list = fileList.length ? fileList : DEFAULT_FILES;
|
||||
list.forEach(function (filePath) {
|
||||
filePath = path.resolve(BASE_DIR, filePath);
|
||||
less2css(filePath);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function compileLess(code, options, onsuccess) {
|
||||
less.render(code, options).then(function (output) {
|
||||
onsuccess(output.css);
|
||||
}, function (error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
function less2css(filePath) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new Error('file not exist:' + filePath);
|
||||
}
|
||||
var paths = [
|
||||
__dirname
|
||||
];
|
||||
var options = {
|
||||
relativeUrls: true,
|
||||
compress: true,
|
||||
paths: paths,
|
||||
filename: filePath
|
||||
};
|
||||
compileLess(fs.readFileSync(filePath, 'utf-8'), options, function (code) {
|
||||
fs.writeFileSync(filePath.replace(/\.less$/, '.css'), code);
|
||||
console.log('build less success:' + filePath);
|
||||
});
|
||||
}
|
||||
@@ -25,8 +25,9 @@ function format(source, data) {
|
||||
|
||||
|
||||
module.exports = function main(tpl) {
|
||||
let language = String(this.resource).match(/\?en-us/) ? 'en-us' : 'zh-cn';
|
||||
let i18n = {};
|
||||
i18n.lang = require('./i18n.zh-cn');
|
||||
i18n.lang = require('./i18n.' + language);
|
||||
let fileContent = format(tpl, i18n);
|
||||
return 'module.exports=' + JSON.stringify(fileContent);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user