2017-10-11 218 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夾中的文件,流星並不在一個新的閉包加載它們,這樣他們就可以自由地污染全局範圍。