目前我正在使用require.js进行一个有趣的副业项目,除了一个名为prism.js的代码语法高亮插件外,一切都正常工作。我可以看到该插件通过chrome的网络选项卡被拉取,但插件没有初始化。
我不确定是require的问题还是插件的问题,想知道是否有人可以帮忙解决。
这是我的main.js:
require.config({
// 3rd party script alias names
paths: {
// Core Libraries
modernizr: "libs/modernizr",
jquery: "libs/jquery",
underscore: "libs/lodash",
backbone: "libs/backbone",
handlebars: "libs/handlebars",
text: "libs/text",
prism: "plugins/prism",
templates: "../templates"
},
// Sets the configuration for your third party scripts that are not AMD compatible
shim: {
"backbone": {
"deps": ["underscore", "jquery", "handlebars"],
"exports": "Backbone" //attaches "Backbone" to the window object
}
}
});
// Include Specific JavaScript
require(['prism', 'modernizr', 'jquery', 'backbone', 'routers/router', 'views/AppVIew' ],
function(Prism, Modernizr, $, Backbone, Router, App) {
this.router = new Router();
this.App = new App();
}
);
require('prism');
或在参数中将其包含为依赖项define
。 - Chris Salzberg