# Code compilation
# Compile JS code to ES5
With this option on, the developer tools will use babel to compile the JS code into ES5 standard code to meet the requirements of running on a lower version of the phone system.
After version 1.05.2106091 of the tool, the original
ES6 to ES5andenhanced compilationsoptions are consolidated ascompiling the JS code into ES5, which is consistent with the originalenhanced compilationlogic.For older versions of the documentation, see here .
Function explaination:
- Based on the babel7 implementation, using
preset-env,Supports the latestECMAScriptsyntax, compiled to{chrome: 53, ios: 8} - Share Babel auxiliary functions, which are located by default in the project
@ babel / runtimedirectory, via the project configuration file configuration - Support async / await syntax, inject
regeneratorRuntimeon 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;Starting with version 1.05.2108172,setting.disableUseStrictin project.config.jsonWhentrue, strict mode can be disabled globally without having to deal with individual files separately. - You can specify any file or directory without compilation (e.g. miniprogram_npm) through the
project configuration file - The original logic supports the
stage0syntax, and for forward compatibility, introduces a series of proposal plug-ins - With regard to polyfill, a large number of
es6related 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
- For Weixin Mini Program only simple pages, turn on this function does not work well
- A file larger than 500kb that uses
requireto refer to a file in a project may report that the file was not found at runtime - Dynamic reference cases such as
vara = 'somefile.js'; require(a); - The case where the
requirefunction to another variable, such asvar a = require; a('somefile.js'); - The case where
requireas a parameter to a binary operator, e.g.require + 1; - 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.
# Native support for compiling TypeScript
Tools improve support for typescript projects by compiling plug-ins.
Instead of having both ts files and js files in the Typescript project, the new template only needs to create ts files, and no need to generate js files with the same name. The new template does not need to execute the npm runtsc command before each compilation. In addition, the tool supports compiling less or sass files into wxss files.Please see Native Support for TypeScript