2017-10-11 221 views
1

我是新与流星的工作,我试图导入JavaScript文件:skel.min.js,skel中,layout.min.js和skel中,viewport.min.js到项目。SKEL进口流星项目

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

我有基地布局在 “客户端/的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. 

[email protected]    # Packages every Meteor app needs to have 
[email protected]  # Packages for a great mobile UX 
[email protected]     # The database Meteor supports right now 
[email protected] # Compile .html files into Meteor Blaze views 
[email protected]   # Reactive variable for tracker 
[email protected]     # Meteor's client-side reactive programming library 

[email protected] # CSS minifier run for production mode 
[email protected] # JS minifier run for production mode 
[email protected]    # ECMAScript 5 compatibility for older browsers 
[email protected]    # Enable ECMAScript2015+ syntax in app code 
[email protected]   # Server-side component of the `meteor shell` command 

[email protected]    # Allow all DB writes from clients (for prototyping) 
iron:router 
twbs:bootstrap 
rlespagnol:skeleton-css 
johnantoni:meteor-skeleton 
jquery 
fourseven:scss 

感谢

回答

2

貌似这个问题是不是你的代码,你贴出来,但是当流星急切地将文件加载它做了两两件事。

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

除此之外,因为skel.min使用UMD模式和流星使用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夹中的文件,流星并不在一个新的闭包加载它们,这样他们就可以自由地污染全局范围。