javascript - meteor 项目中的 Skel 导入

标签 javascript meteor skel

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

这3个文件在client/js路径下(client/js/skel.min.js, client/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

感谢

最佳答案

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

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

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

查看 skel 存储库中的代码,skel-layoutskel-viewport 不使用 UMD 或尝试 require()import skel,它只是希望它在当前范围内可用。

换句话说。 Skel 半途而废了他们的模块模式。

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

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

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

关于javascript - meteor 项目中的 Skel 导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46678617/

相关文章:

javascript - 如何从 Promise 引用 Angular 服务的变量然后在服务内部运行?

javascript - 无法在 linux 中运行 npx react-native init

javascript - 从 Firebase 存储获取图像并放入 PDF

Javascript 数组和 Meteor session

javascript - 获取 Meteor 中集合的索引列表

javascript - SkelJS - 不同的行偏移量,每个特定断点一个

javascript - 使用 ajax 表单的简单 jQuery 就地编辑

javascript - React 路由器与 Meteor : How to remove code param from URL after redirect from OAuth without reload

jquery - 我怎样才能得到左边的按钮?

javascript - Skel js 折叠导航不工作 iOS