Home > Web Front-end > JS Tutorial > body text

babel-loader file preprocessor usage instructions

php中世界最好的语言
Release: 2018-05-08 18:08:44
Original
1660 people have browsed it

This time I bring you instructions for using the babel-loader file preprocessor. What are the precautions when using the babel-loader file preprocessor? Here are practical cases, let’s take a look.

Today we are introduced to babel-loader, which is used to process ES6 syntax and compile it into js syntax that the browser can execute.

Installation

We need to use babel-loader babel-core babel-preset

Compatible version: webpack 3. x | babel-loader 8.x | babel 7.x

npm install babel-loader@8.0.0-beta.0 @babel/core @babel/preset-env webpack
webpack 3.x babel-loader 7.x | babel 6.x
Copy after login

Use

Let’s start with a little chestnut:

var htmlWebpackPlugin = require('html-webpack-plugin')
const path = require('path')
module.exports = {
  mode: 'development',
  entry: './src/app.js',
  output: {
    filename: 'js/bundle.js',
    path: path.resolve(dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/, // (不处理node_modules 和 bower_components下的js文件) 优化处理加快速度
        use: {
          loader: 'babel-loader',
          options: {     // options选项中的presets设置的就是当前js的版本
            presets: ['@babel/preset-env']
          }
        }
      }
    ]
  },
  plugins: [
    new htmlWebpackPlugin({
      template: 'index.html',
      inject: 'body',
      filename: 'index.html'
    })
  ]
}
Copy after login

You can use options Attributes to pass options to the loader.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Calling the Baidu map plug-in in Vue

Detailed instructions for using jointjs in vue

Detailed explanation of unit and E2E testing steps with Angular CLI

The above is the detailed content of babel-loader file preprocessor usage instructions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!