2016-07-19 16 views
1

Wir wollen Foundation 6 JS-Plugins in unserer Phoenix/Brunch-App verwenden, aber ich kann nicht herausfinden, wie man Foundation-Skripte richtig einbindet. Soweit ich verstehe, sollten sie nach jQuery geladen werden und wird es mit .foundation() Funktion erweitern.Wie wird Foundation 6 JS in Brunch geladen?

package.json

"dependencies": { 
    "foundation-sites": "^6.2.3", 
    "jquery": "^3.1.0", 
    "sass-brunch": "^2.6.3", 
}, 

Brunch-config.js

exports.config = { 
    files: { 
    javascripts: { 
     joinTo: "js/app.js", 
     order: { 
     before: [ 
      "node_modules/jquery/dist/jquery", 
      "node_modules/foundation-sites/js/foundation.core", 
      "node_modules/foundation-sites/js/foundation.topbar" 
     ] 
     } 
    }, 
    stylesheets: { 
     joinTo: "css/app.css" 
    }, 
    templates: { 
     joinTo: "js/app.js" 
    } 
    }, 

    conventions: { 
    assets: /^(web\/static\/assets)/, 
    ignored: [ 
     /\/_.*/ 
    ] 
    }, 
    paths: { 
    watched: [ 
     "web/static", 
     "test/static" 
    ], 
    public: "priv/static" 
    }, 

    plugins: { 
    babel: { 
     ignore: [/web\/static\/vendor/, /web\/static\/elm/] 
    }, 
    eslint: { 
     pattern: /^web\/static\/js\/.*\.js?$/ 
    }, 
    sass: { 
     mode: 'native', 
     options: { 
     includePaths: [ 
      'node_modules/foundation-sites/scss' 
     ] 
     } 
    } 
    },  

    modules: { 
    autoRequire: { 
     "jquery":   "node_modules/jquery/dist/jquery", 
     "foundation_core": "node_modules/foundation-sites/js/foundation.core", 
     "foundation_topbar": "node_modules/foundation-sites/js/foundation.topbar", 
     "js/app.js":   ["web/static/js/app"] 
    } 
    }, 

    npm: { 
    enabled: true, 
    whitelist: ["phoenix", "phoenix_html", "jquery", "foundation-sites", "scrollreveal"], 
    globals: { 
     $:  'jquery', 
     jQuery: 'jquery', 
    } 
    } 
}; 

Der Brunch Dokumentation nicht sehr explizit ist so könnte ich ein paar Fehler in dieser Konfiguration machen (wenn versucht, autoRequire und npm.globals zu benutzen - was sind Kartenschlüssel dort?), aber dennoch $ und jQuery globale Variablen sind t hier und zeigt auf die jQuery-Bibliothek, was in Ordnung ist.

Das Problem ist, dass $(document).foundation nicht definiert ist.

Antwort

0

Brunch hat kein Aktiva zusammengestellt, Ursache im Abschnitt „Module“ verwendet, um Sie String-Werte:

modules: { 
    autoRequire: { 
     "jquery":   "node_modules/jquery/dist/jquery", 
     "foundation_core": "node_modules/foundation-sites/js/foundation.core", 
     "foundation_topbar": "node_modules/foundation-sites/js/foundation.topbar", 
     "js/app.js":   ["web/static/js/app"] 
    } 
}, 

stattdessen sollten Sie ein Array von Strings mit Pfaden verwenden. Also, ändern Sie es in:

modules: { 
    autoRequire: { 
     "jquery":   ["node_modules/jquery/dist/jquery"], 
     "foundation_core": ["node_modules/foundation-sites/js/foundation.core"], 
     "foundation_topbar": ["node_modules/foundation-sites/js/foundation.topbar"], 
     "js/app.js":   ["web/static/js/app"] 
    } 
},