NPM + Zurb Foundation + WebPack: Cannot resolve module 'foundation'

前端 未结 10 2182
挽巷
挽巷 2020-12-23 17:59

I am working on using Zurb Foundation with WebPack and NPM, without Bower.

The problem I am encountering is the same as this below:

https://github.c

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 18:24

    I have same problem, but I don't want have two .js files (vendor and app)!

    For me, everything need be on a single file, so, I make this:

    In webpack.conf.js, use externals (maybe have another way without external, but for me, this is sufficient):

    externals: {
        jQuery: 'jQuery',
        foundation: 'Foundation'
    },
    

    create a file in your source folder (any name, like /libs/foundation.js):

    // jQuery
    var $ = require('jquery');
    global.jQuery = $;
    
    // if you want all features of foundation
    require('./node_modules_folder/foundation-sites/dist/foundation.js');
    
    // if you want only some features
    // require('./node_modules/what-input/what-input');
    // require('./node_modules/foundation-sites/js/foundation.core');
    // require('./node_modules/foundation-sites/js/....');
    
    export default Foundation;
    

    now, you can use Foundation in any js using following syntax:

    import Foundation from './libs/foundation';
    

提交回复
热议问题