Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transpile code in .vue file to ES5 #605

Closed
zzzgit opened this issue Jan 29, 2017 · 4 comments
Closed

transpile code in .vue file to ES5 #605

zzzgit opened this issue Jan 29, 2017 · 4 comments

Comments

@zzzgit
Copy link

zzzgit commented Jan 29, 2017

{
  entry: './src/index.js',
  output: {
    path: __dirname+"/dist/",
    filename: "build.js",
    
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: "vue-loader",
        options: {
          buble: {
            objectAssign: 'Object.assign',
            transforms: {
              stripWith: false
            }
          }
        }
      },
      {
        test: /\.css$/,
        loader: "style-loader!css-loader"
      },
      {
        test: /\.jpg$/,
        loader: "file-loader"
      },
      {
        test: /\.png$/,
        loader: "file-loader"
      },
      {
        test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
        loader: 'file-loader'
      },
      {
        test: /\.js?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: [
            'es2015'
          ]
        }
      }
    ]
  },
  plugins: [
    
  ],
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.common.js'
    }
  },
}

only code in the .js file could be transpiled to ES5
code in .vue file will not be transpiled
why?

@zzzgit
Copy link
Author

zzzgit commented Jan 29, 2017

and,i don't have a .babelrc file in my project
is it the reason?

@zzzgit
Copy link
Author

zzzgit commented Jan 29, 2017

yes it works after adding a .babelrc file to the project
but why?

image

image

adding a .babelrc,is it the only way to config ES6 transpilation support for .vue?
is there a way to config it in the webpack.config.js file?

@barraponto
Copy link

@zzzgit never tried, but... did you try:

module.exports = {
  // other options...
  module: {
    // module.rules is the same as module.loaders in 1.x
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        // vue-loader options goes here
        options: {
          loaders: {
            'js': 'babel-loader'
          }
        }
      }
    ]
  }
}

It is documented in http://vue-loader.vuejs.org/en/configurations/advanced.html

@kazupon
Copy link
Member

kazupon commented Jan 30, 2017

Please make sure to read the Issue Reporting Guidelines before opening new issues. The issue list only accepts bug reports and feature requests. Questions should be posted to the Gitter chat room, forum or StackOverflow.


As @barraponto mentioned, You can configure at vue options. see the vue-loader docs and babel-loader docs

Thanks.

@kazupon kazupon closed this as completed Jan 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants