amazon-archives / amazon-cognito-auth-js

The Amazon Cognito Auth SDK for JavaScript simplifies adding sign-up, sign-in with user profile functionality to web apps.
Apache License 2.0
423 stars 232 forks source link

Integrating with vue.js webpack #1

Open konstantinvlasenko opened 7 years ago

konstantinvlasenko commented 7 years ago

Hi,

I've installed npm install --save https://github.com/aws/amazon-cognito-auth-js/tarball/master I am having this webpack.base.conf.js file. But it still complaints that file amazon-cognito-auth-js can't be found :( Maybe some obvious issue with my configuration?

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
  },
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      '@': resolve('src')
    }
  },
  module: {
    rules: [
      {
        test: /\.(js|vue)$/,
        loader: 'eslint-loader',
        enforce: 'pre',
        include: [resolve('src'), resolve('test')],
        options: {
          formatter: require('eslint-friendly-formatter')
        }
      },
      {
        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',
        options: {
          limit: 10000,
          name: utils.assetsPath('img/[name].[hash:7].[ext]')
        }
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,
          name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
        }
      }
    ]
  }
}
mymattcarroll commented 6 years ago

@konstantinvlasenko I think I was having the same issue as you using webpack but with AngularJS. Fix was to not rely on the file package.json is pointing to which does not exist. Ended up using this import statement as a work around:

import CognitoAuth from 'amazon-cognito-auth-js/src/CognitoAuth.js'

Hope this helps.

yuntuowang commented 6 years ago

If your project uses React structure, this will work: import CognitoAuth from 'amazon-cognito-auth-js/src/CognitoAuth.js'