找到build下webpack.base.conf.js文件修改配置

var webpack = require('webpack')
var path = require('path')
var utils = require('./utils')
var config = require('../config')
var vueLoaderConfig = require('./vue-loader.conf')

function resolve (dir) {
  return path.join(__dirname, '..', dir)
}

module.exports = {
  entry: {
    app: './src/main.js'
  },

  output: {
    path: config.build.assetsRoot,
    filename: '[name].js',
    publicPath: process.env.NODE_ENV === 'production'
      ? config.build.assetsPublicPath
      : config.dev.assetsPublicPath
  },
 /* externals: {
    'zepto' : '$'
  },*/
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src'),
      'assets': resolve('src/assets'),
      'router': resolve('src/router'),
      'components': resolve('src/components'),
      //'zepto': resolve('src/assets/lib/zepto.min.js'),
      'zepto': resolve('src/assets/scripts/lib/zepto.min.js')
      //'zepto': 'zepto'
    }
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: vueLoaderConfig
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        include: [resolve('src'), resolve('test')]
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        query: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        query: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      },
      {
        test: resolve('src/assets/scripts/lib/zepto.min.js'),
        loader: 'exports-loader?window.$!script-loader'
      }
    ]
  },
  plugins: [
    new webpack.ProvidePlugin({
      $: resolve('src/assets/scripts/lib/zepto.min.js'),
      Zepto: resolve('src/assets/scripts/lib/zepto.min.js'),
      "window.Zepto": resolve('src/assets/scripts/lib/zepto.min.js')
    })
  ]
}
注意Zepto项就行
二、回到项目根目录安装

npm install exports-loader script-loader --save-dev --verbose


三、在main.js里新增

import Zepto from 'assets/scripts/lib/zepto.min'
即可
 

Logo

前往低代码交流专区

更多推荐