因此,我将PNotify从bower导出到js文件夹。我使用requirejs来包含我的库
<script data-main="assets/js/app" type="text/javascript" src="assets/js/lib/require.js"></script>我的建筑是这样的:
js
--- app.js
--- lib
------ pnotify.core.js
------ pnotify.desktop.js
------ pnotify.buttons.js
------ pnotify.callbacks.js
------ pnotify.confirm.js
------ pnotify.history.js
------ pnotify.nonblock.js
------ pnotify.reference.js
------ jquery.js
------ ...我添加了主模块,即pnotify.core
APP.JS
requirejs.config({
base: '/assets/js',
paths: {
'jQuery': 'lib/jquery.min',
'underscore': 'lib/underscore-min',
'Backbone': 'lib/backbone',
'Modernizr' : 'lib/modernizr',
'PNotify' : 'lib/pnotify.core',
'LoginView' : 'views/login'
},
shim: {
'jQuery': {
exports: '$'
},
'underscore': {
exports: '_'
},
'Backbone': {
exports: 'Backbone'
},
'Modernizr': {
exports: 'Modernizr'
},
'LoginView': {
exports: 'LoginView'
},
'PNotify': {
exports: 'PNotify'
}
}
});PNotify被加载到我的页面中。通常,PNotify使用的是需求:https://github.com/sciactive/pnotify#using-pnotify-with-requirejs。
我不知道如何导入所有模块,也许可以在一个文件pnotify.min.js中连接这些模块?
在这里,当我在PNotify下调用requirejs.config对象时
define(['jQuery', 'underscore', 'Backbone', 'Modernizr', 'LoginView', 'PNotify'], function ($, _, Backbone, Modernizr, LoginView, PNotify) {
$(document).ready(function(){
new PNotify({
title: 'Desktop Notice',
text: 'If you\'ve given me permission, I\'ll appear as a desktop notification. If you haven\'t, I\'ll still appear as a regular PNotify notice.'
});
});
});我有一个错误:Uncaught TypeError: undefined is not a function在行“新PNotify”.
你有什么想法吗?
发布于 2014-09-29 19:12:51
当他们检测到AMD/RequireJS时,PNotify核心定义了命名模块"pnotify",而PNotify的模块分别定义了"pnotify.module“这样的名称。下面的示例演示使用RequireJS的非块模块和桌面模块。
所以我的错误就在这里
requirejs.config({
base: '/assets/js',
paths: {
'jQuery': 'lib/jquery.min',
'underscore': 'lib/underscore-min',
'Backbone': 'lib/backbone',
'Modernizr' : 'lib/modernizr',
'PNotify' : 'lib/pnotify.core',
^_____ 'replace by pnotify'
'LoginView' : 'views/login'
},
...发布于 2015-02-05 03:00:29
将所有模块编译成一个缩小的文件。
这些设置在Require.js中适用于我
paths: {
'pnotify': 'lib/pnotify.min',
'pnotify.nonblock': 'lib/pnotify.min',
'pnotify.desktop': 'lib/pnotify.min,
'jquery' : 'lib/jquery'
}
define(['jquery', 'pnotify','pnotify.nonblock', 'pnotify.desktop', function($, pnotify){
new PNotify({
title: 'Desktop Notice',
text: 'If you\'ve given me permission, I\'ll appear as a desktop notification. If you haven\'t, I\'ll still appear as a regular PNotify notice.',
desktop: {
desktop: true
},
nonblock: {
nonblock: true
}
});
});https://stackoverflow.com/questions/26098194
复制相似问题