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

Release: 2019-11-23 16:21:32
forward
2437 people have browsed it

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
Copy after login

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'));
  }
Copy after login

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!

Related labels:
source:layui.com
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