因此,我从凉亭将PNotify
导出到js
文件夹。我使用requirejs
来包含我的库
HTML
<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适用于requirejs: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
就行&#34;新的PNotify&#34; ...
你有什么想法吗?
答案 0 :(得分:1)
当他们检测到AMD / RequireJS时,PNotify核心定义了命名模块 “ pnotify ”和PNotify的模块各自定义名称 “pnotify.module”。以下示例显示了nonblock的用法 和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'
},
...
答案 1 :(得分:-1)
将所有模块编译成一个缩小的文件。
这些设置适用于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
}
});
});