javascript - 航点 npm - 错误 : Can't resolve 'waypoint

标签 javascript import npm ecmascript-6 vue.js

我有一个vue项目并安装了航点

npm install waypoints

我尝试导入它

import waypoint from 'waypoints';

但是报错

错误:无法解析/Mypath 中的“航点”

我做错了什么?

var webpack = require('webpack');
var path = require('path');
let ExtractTextPlugin = require("extract-text-webpack-plugin");
var WebpackNotifierPlugin = require('webpack-notifier');
var fs = require('file-system');
var CleanWebpackPlugin = require('clean-webpack-plugin');


module.exports = {
/*node: {
  fs: "empty"
},*/
    resolve: {
    alias: {
      'masonry': 'masonry-layout',
      'isotope': 'isotope-layout'
    }
  },

    entry: './main.js',
    devtool: 'source-map',
    output: {
        path: path.resolve(__dirname, './public/assets'),
        filename: 'bundle.[chunkhash].js',
    },

    module: {
        rules: [

         {  test: /\.js$/, 
                exclude: /node_modules/, 
                loader: "babel-loader?presets[]=es2015",

             },

            {
                test:/\.scss$/,
                use: ExtractTextPlugin.extract({
                    use: [{loader:'css-loader?sourceMap'}, {loader:'sass-loader', options: {
                    sourceMap: true,

                }}],

                })
            },   



            {
                 test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },



        ]
    },  

    plugins: [
new CleanWebpackPlugin(['assets/*', 'css/*'], {
            root: '/Users/LEITH/sites/laravelleith/public',
            verbose: true,
            dry: false,
            exclude: ['360lockturret.jpg'],
            watch: true
    }),

        new webpack.optimize.UglifyJsPlugin(),
        new ExtractTextPlugin('app.[chunkhash].css'),
        new WebpackNotifierPlugin(),

        function() {
            this.plugin('done', stats =>{
                fs.writeFileSync(
                    path.join(__dirname, 'manifest.json'),
                    JSON.stringify(stats.toJson().assetsByChunkName)
                )

            });
        }

    ]

};

最佳答案

Waypoints 捆绑了多种风格,甚至通过 NPM,但我不知道是否有默认实现。这就是为什么典型的 import Waypoint from 'waypoints' 指令不起作用的原因。

我为我的“vanilla ES6 + Webpack”设置解决了这个问题,如下所示:

import 'waypoints/lib/noframework.waypoints.min.js';

const waypoint = new Waypoint({
  element: document.getElementById('myScrollTarget'),
  handler: () => {}
});

关于javascript - 航点 npm - 错误 : Can't resolve 'waypoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43282985/

相关文章:

reactjs - NPM 带宽使用情况

reactjs - 通过 jest 运行测试,我在包含的 .jsx 文件中得到 `Unexpected token`

javascript - 弹出菜单的 slideToggle

python - import tkinter as tk 和 from tkinter import 的区别

node.js - 最新的 npm 版本在 Linux 中不起作用

sql-server - 制作 SQL Server 转储并将该转储导入另一个 SQL Server 的最佳(最简单)方法

javascript - 从姊妹文件 Node.JS 导入函数

javascript - 具有相同类的元素 id 的数组

javascript - 更改 FullCalendar 中的资源

javascript - Vue.js 中的动态导航组件