简体   繁体   English

流星项目中的Skel导入

[英]Skel import in Meteor Project

I'm new working with Meteor, I'm trying to import a javascript file: skel.min.js, skel-layout.min.js and skel-viewport.min.js into a project. 我是Meteor的新手,正在尝试将javascript文件导入:skel.min.js,skel-layout.min.js和skel-viewport.min.js到项目中。

The 3 files are on the client/js path ( client/js/skel.min.js , client/js/skel-layout.min.js and client/js/skel-viewport.min.js ). 这三个文件位于client / js路径上( client/js/skel.min.jsclient/js/skel-layout.min.jsclient/js/skel-viewport.min.js )。

I have the base layout in "client/baseLayout/baseLayout.js" and I deliver as follows: 我在“ 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)'
    });
.
.
.

But it always shows me the following error: 但这总是向我显示以下错误:

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

I tried to move the files but it does not work either. 我试图移动文件,但是它也不起作用。

What am I doing wrong? 我究竟做错了什么?

My packages: 我的包裹:

# 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

to thank 感谢

Looks like the issue isn't your code that you posted, but when Meteor eagerly loads files it does two things. 看起来问题不是您发布的代码,但是当Meteor急切地加载文件时,它会执行两项操作。

  1. It loads them alphabetically, so skel-layout is running before skel.min which is the error in your console. 它按字母顺序加载,因此skel-layoutskel.min之前运行,这是控制台中的错误。 skel.min needs to run first. skel.min需要首先运行。
  2. It wraps them in a new closure, so they don't pollute the global namespace. 它将它们包装在一个新的闭包中,因此它们不会污染全局名称空间。

In addition to that, because skel.min uses the UMD pattern and Meteor uses common.js, it registers itself with the module loader so it can be called with require() , instead of loading itself onto the window global. 除此之外,由于skel.min使用UMD模式,而Meteor使用common.js,它在模块加载器中注册自身,因此可以使用require()进行调用,而不是将自身加载到全局窗口中。

Looking at the code in the skel repo, skel-layout and skel-viewport doesn't use UMD or attempt to require() or import skel, it just expects it to be available in the current scope. 查看skel repo, skel-layoutskel-viewport中的代码不使用UMD或尝试使用require()import skel,它只是希望它在当前范围内可用。

In other words. 换一种说法。 Skel have half-arsed their module pattern. 斯凯尔(Skel)已将其模块模式提高一半。

Thankfully there's a quick fix. 幸运的是,有一个快速修复。 Put all three files in the client/compatibility folder and prefix the names with the load order: 将所有三个文件放在client/compatibility文件夹中,并在名称前加上加载顺序:

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

For files in the compatibility folder, Meteor doesn't load them in a new closure and so they can freely pollute the global scope. 对于compatibility文件夹中的文件,Meteor不会将它们加载到新的关闭文件中,因此它们可以自由地污染全局范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM