Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added some documentation about the ESM usage
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# ESM Upgrade Path | ||
As of version 10, this plug-in uses the syntax of [ECMAScript modules](https://nodejs.org/api/esm.html). This is a major change: your [Gulp](https://gulpjs.com) script will not work as usual. | ||
|
||
If you don't modify it, you will see this kind of errors: | ||
|
||
``` | ||
SyntaxError: Unexpected token { | ||
``` | ||
|
||
You have 2 choices: | ||
|
||
- continue to use version 9: as long as ES modules are marked as experimental, this is the recommended solution. | ||
- port your Gulp script to ES modules. | ||
|
||
If you choose the second option, here are the steps to follow. | ||
|
||
## Install the `esm` package | ||
Gulp does not natively support ES modules, but it is able to work with them thanks to the [`esm` package](https://www.npmjs.com/package/esm). Modify your project to add this additional dependency: | ||
|
||
```shell | ||
npm install --save-dev esm | ||
``` | ||
|
||
## Rewrite your Gulp script | ||
In order for Gulp to recognize that you are using ES modules, you must rename your `gulpfile.js` file to` gulpfile.esm.js`. | ||
|
||
Then, all you have to do is rewrite the `require` statements as `import` ones. | ||
|
||
```js | ||
// Before: CommonJS syntax. | ||
const gulp = require('gulp'); | ||
const {phpMinify} = require('@cedx/gulp-php-minify'); | ||
|
||
// After: ESM syntax. | ||
import gulp from 'gulp'; | ||
import {phpMinify} from '@cedx/gulp-php-minify'; | ||
``` | ||
|
||
That's it! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters