简体   繁体   中英

How to import a specific variation of an npm package

I'm trying to use Cubic iScroll Infinite Scrolling with ES6 imports. I have the base IScroll working fine however I want to get to the extended functionality of Infinite Scrolling which is inside the repo. But have no idea how to import it.

I'm using the following to import the base. I've tried numerous others that all fail to import.

@import IScroll from 'iscroll'

Variations available include:

  • iscroll-infinite.js <-- Trying to import this variation.
  • iscroll-lite.js
  • iscroll-probe.js
  • iscroll-zoom.js
  • iscroll.js

Considering that I was using WebPack, after searching through the webpack.conf.js files i found that it was setup as this:

resolve: {
    extensions: ['', '.js', '.vue'],

    // THIS LINE IS WHAT I WAS LOOKING FOR:
    fallback: [path.join(__dirname, '../node_modules')],

    alias: {
      'src': path.resolve(__dirname, '../src'),
      'assets': path.resolve(__dirname, '../src/assets'),
      'components': path.resolve(__dirname, '../src/components')
    }
  },

So to get to the specific variations I imported using:

import IScroll from 'iscroll/build/iscroll-infinite'

This seems to be doing exactly what I expected which is loading the package from full path:

../node_modules/iscroll/build/iscroll-infinite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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