1

我是 Meteor 的新手,我正在尝试将一个 javascript 文件:skel.min.js、skel-layout.min.js 和 skel-viewport.min.js 导入到一个项目中。

这 3 个文件位于 client/js 路径(client/js/skel.min.jsclient/js/skel-layout.min.jsclient/js/skel-viewport.min.js上。

我在“client/baseLayout/baseLayout.js”中有基本布局,我交付如下:

import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import * as skel from '../js/skel.min.js';


(function ($) {
    skel.breakpoints ({
        xlarge: '(max-width: 1680px)',
        large: '(max-width: 1280px)',
        medium: '(max-width: 980px)',
        small: '(max-width: 736px)',
        xsmall: '(max-width: 480px)',
        'xlarge-to-max': '(min-width: 1681px)',
        'small-to-xlarge': '(min-width: 481px) and (max-width: 1680px)'
    });
.
.
.

但它总是向我显示以下错误:

Uncaught ReferenceError: skel is not defined
    at skel-layout.min.js (app.js? hash = e2c356f13dbdbc8f5ea02b405b7c429aff6b8bef: 699)
    at fileEvaluate (modules-runtime.js? hash = 8587d188e038b75ecd27ed2469a52b269e38fb62: 343)
    at require (modules-runtime.js? hash = 8587d188e038b75ecd27ed2469a52b269e38fb62: 238)
    at app.js? hash = e2c356f13dbdbc8f5ea02b405b7c429aff6b8bef: 1157

我试图移动文件,但它也不起作用。

我究竟做错了什么?

我的包裹:

# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.

meteor-base@1.1.0             # Packages every Meteor app needs to have
mobile-experience@1.0.5       # Packages for a great mobile UX
mongo@1.2.2                   # The database Meteor supports right now
blaze-html-templates@1.0.4 # Compile .html files into Meteor Blaze views
reactive-var@1.0.11            # Reactive variable for tracker
tracker@1.1.3                 # Meteor's client-side reactive programming library

standard-minifier-css@1.3.5   # CSS minifier run for production mode
standard-minifier-js@2.1.2    # JS minifier run for production mode
es5-shim@4.6.15                # ECMAScript 5 compatibility for older browsers
ecmascript@0.8.3              # Enable ECMAScript2015+ syntax in app code
shell-server@0.2.4            # Server-side component of the `meteor shell` command

insecure@1.0.7                # Allow all DB writes from clients (for prototyping)
iron:router
twbs:bootstrap
rlespagnol:skeleton-css
johnantoni:meteor-skeleton
jquery
fourseven:scss

感谢

4

1 回答 1

2

看起来问题不在于您发布的代码,但是当 Meteor 急切地加载文件时,它会做两件事。

  1. 它按字母顺序加载它们,因此skel-layout运行之前skel.min是控制台中的错误。skel.min需要先运行。
  2. 它将它们包装在一个新的闭包中,因此它们不会污染全局命名空间。

除此之外,因为skel.min使用 UMD 模式并且 Meteor 使用 common.js,所以它使用模块加载器注册自己,因此可以使用 调用它require(),而不是将自己加载到全局窗口中。

查看skelrepo 中的代码,skel-layout并且skel-viewport不使用 UMD 或尝试require()importskel,它只是希望它在当前范围内可用。

换句话说。Skel 已经对他们的模块模式做了一半。

谢天谢地,有一个快速修复。将所有三个文件放在client/compatibility文件夹中,并在名称前加上加载顺序:

1-skel.min.js
2-skel-layout.min.js
3-skel-viewport.min.js

对于文件compatibility夹中的文件,Meteor 不会将它们加载到新的闭包中,因此它们可以随意污染全局范围。

于 2017-10-11T04:25:43.503 回答