Webpack + Vuejs + GSAP问题

时间:2017-12-21 12:45:36

标签: webpack vue.js gsap

通过GSAP安装npm时出现此问题 我正在使用webpack-vuecli

中的基本github模板

错误是:

  

__ WEBPACK_IMPORTED_MODULE_0_gsap___default.a.to不是函数

在我的组件中我导入它

  import TweenMax from 'gsap';

然后在类似这样的方法中使用它

 typeText() {
    TweenMax.to('#header-line-1', 1, { x: 500 });
  }

这是我的webpack配置文件

'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
   const vueLoaderConfig = require('./vue-loader.conf')

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

const createLintingRule = () => ({
  test: /\.(js|vue)$/,
  loader: 'eslint-loader',
  enforce: 'pre',
  include: [resolve('src'), resolve('test')],
  options: {
    formatter: require('eslint-friendly-formatter'),
    emitWarning: !config.dev.showEslintErrorsInOverlay
  }
})

module.exports = {
  context: path.resolve(__dirname, '../'),
  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
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      'vue$': 'vue/dist/vue.esm.js',
      '@': resolve('src')
    }
  },
  module: {
rules: [
  ...(config.dev.useEslint ? [createLintingRule()] : []),
  {
    test: /\.vue$/,
    loader: 'vue-loader',
    options: vueLoaderConfig
  },
  {
    test: /\.js$/,
    loader: 'babel-loader',
    include: [resolve('src'), resolve('test')]
  },
  {
    test: /\.(png|jpe?g|gif)(\?.*)?$/,
    loader: 'url-loader',
    options: {
      limit: 10000,
      name: utils.assetsPath('img/[name].[hash:7].[ext]')
    }
  },

下面还有其他规则我认为它们不是我的问题所必需的

1 个答案:

答案 0 :(得分:0)

TweenMax不是默认导出。

这应该有效:

import { TweenMax } from 'gsap/all'
const anim = [TweenMax] // eslint-disable-line (prevent tree shake)