# Code compilation

The tool provides the following code compilation capabilities

# ES6 转 ES5

In 0.10.101000 and later,babelis used by defaultConvert developers'ES6syntax code intoES5code that is well supported at all three ends to help developers solve development problems associated with different environments.

Please note:

  • To improve code quality, when theES6conversion function is turned on, thejavasctiptstrict mode is enabled by default. Refer to "use strict"

# Enhanced compilation

In the 1.02.1904282 and later development tools,enhanced compilationTheoption enhances theES6 to ES5capabilities, and when enabled, uses new compilation logic and provides additional options for developers.

Enableto enhance the compilation capability of

Characteristic The original logic Enhanced compilation
Babel version babel6 babel7
Presets es2015、stage0 env {chrome:53, ios:8}
Helpers Single file inline Sharing across files
Async/Await No support. Support
Strict Mode Switch No support. Support
Ignore the file directory No support. Support
Code compression uglify-js terser
Babel plugin - A series of proposal*
polyfill Most es6 Three new polyfill*
  • Usingpreset-env, supporting the latestECMAScriptsyntax
  • Share Babel auxiliary functions, which are located by default in the project@ babel / runtimedirectory, via the project configuration file configuration
  • Support async / await syntax, injectregeneratorRuntimeon demand, directory location consistent with auxiliary functions
  • The first line of the file is/ / use strict disable;, you can disable the current file strict mode
  • You can specify any file or directory without compilation (e.g. miniprogram_npm) through theproject configuration file
  • The original logic supports thestage0syntax, and for forward compatibility, introduces a series of proposal plug-ins
  • With regard to polyfill, a large number ofes6related polyfills can be referenced in the documentation under enhanced compilation, adding:Array.prototype.includes(es7)、Object.entries(es8)、Object.values(es8)

# Style Completion

When this option is turned on, the development tool automatically detects and corrects missing styles to ensure a normal display on lower-version systems.Although most of the problems can be circumvented, it is recommended that developers check the true performance of Weixin Mini Program separately on iOS and Android.

# Compression code

With this option on, developer tools will help developers compress and obfuscatejavascriptcode when uploading code, reducing the size of the package.

# Code Protection

When this option is turned on, the developer tool attempts to protect the project code, mainly by flattening the file and replacing the filenames referred to byrequire. This feature is not suitable for the following circumstances

  1. For Weixin Mini Program only simple pages, turn on this function does not work well
  2. A file larger than 500kb that usesrequireto refer to a file in a project may report that the file was not found at runtime
  3. Dynamic reference cases such asvara = 'somefile.js'; require(a);
  4. The case where therequirefunction to another variable, such asvar a = require; a('somefile.js');
  5. The case whererequireas a parameter to a binary operator, e.g.require + 1;
  6. Using the...operator and not turning on ES6 to ES5

# Enable multicore compilation

This option is visible on computers with four cores and above. Enabling this option will make full use of CPU resources to compile the project's JS code and improve the efficiency of compilation. You can choose to turn this off.