Home >Web Front-end >Layui Tutorial >Introduction to how to make layui support es5 writing method

Introduction to how to make layui support es5 writing method

尚
forward
2019-11-23 16:21:322424browse

Introduction to how to make layui support es5 writing method

When writing js, I will write some es5 code, but when I package it into dist, I find that the syntax is not supported. What should I do?

Two steps to add es5 support:

1. Use npm to download and install babel, and enter the directory where gulpfile.js is located.

$ npm install --save-dev gulp-babel @babel/core @babel/preset-env

2. Modify gulpfile.js code in 2 places.

var gulp = require('gulp');
var babel = require('gulp-babel'); // 添加这段代码

// ...

 //压缩 JS
  minjs: function(){
    // 修改下面这段代码
    return gulp.src(src).pipe(babel({
      presets: ['@babel/env']
    })).pipe(uglify())
     .pipe(header.apply(null, note))
    .pipe(gulp.dest(destDir + '/layuiadmin'));
  }

Then you can enter gulp as before to complete the construction of src to the dist directory.

For more knowledge about layui framework, please pay attention to layui tutorial.

The above is the detailed content of Introduction to how to make layui support es5 writing method. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:layui.com. If there is any infringement, please contact admin@php.cn delete