更改requireJS,使其不会在intern.js上自动添加.js文件扩展名
目前我在intern.js的定制html reporter中工作。我使用的模板引擎是marko.js。 js有扩展名文件“.marko”供我输入html语法 文件在normal node.js(common.js)中正确生成 问题发生在我将相同的代码集成到intern.js时。internjs使用的requirejs(AMD)在我这样做时会自动将.js文件扩展名添加到我的marko扩展名中更改requireJS,使其不会在intern.js上自动添加.js文件扩展名,requirejs,amd,intern,marko,Requirejs,Amd,Intern,Marko,目前我在intern.js的定制html reporter中工作。我使用的模板引擎是marko.js。 js有扩展名文件“.marko”供我输入html语法 文件在normal node.js(common.js)中正确生成 问题发生在我将相同的代码集成到intern.js时。internjs使用的requirejs(AMD)在我这样做时会自动将.js文件扩展名添加到我的marko扩展名中 var template = require('./hello-world.marko'); 这使得文件
var template = require('./hello-world.marko');
这使得文件变成helloworld.marko.js
,这导致代码在markojs中中断
下面是自定义html reporter代码
define(function (require) {
// require('intern/dojo/node!marko/node-require').install();
var fs = require('intern/dojo/node!fs');
var template = require('./hello-world.marko');
console.log(template);
function JsonReporter(config) {
config = config || {};
this.output = config.output;
}
JsonReporter.prototype = {
runEnd(executor) {
// console.log("toJson: " + JSON.stringify(executor.suites))
data = JSON.stringify(executor.suites);
template.renderToString(data,
function (err, output) {
console.log(output);
fs.writeFile('result.html', output, function (err) {
if (err) return console.log(err);
console.log('Save done');
});
});
},
}
return JsonReporter;
})
require
函数实际上并不用于在节点的加载器或AMD加载器中加载任意文本资源。在节点中,无论您是否运行Intern,都可以使用fs.readFile
或fs.readFileSync
。在Intern基于Dojo的AMD环境中,您还可以使用Dojo/text
loader插件,如下所示:
var template = require('dojo/text!./hello-world.marko');