Skip to content

Commit

Permalink
Core: Migrate from AMD to ES modules 🎉
Browse files Browse the repository at this point in the history
Migrate all source AMD modules to ECMAScript modules. The final bundle
is compiled by a custom build process that uses Rollup under the hood.

Test files themselves are still loaded via RequireJS as that has to work in
IE 11.

Tests can now be run in "Load as modules" mode which replaces the previous
"Load with AMD" option. That option of running tests doesn't work in IE
and Edge as it requires support for dynamic imports.

Some of the changes required by the migration:
* check `typeof` of `noGlobal` instead of using the variable directly
  as it's not available when modules are used
* change the nonce module to be an object as ECMASscript module exports
  are immutable
* remove some unused exports
* import `./core/parseHTML.js` directly in `jquery.js` so that it's not
  being cut out when the `ajax` module is excluded in a custom compilation

Closes gh-4541
  • Loading branch information
mgol committed Nov 18, 2019
1 parent a612733 commit d0ce00c
Show file tree
Hide file tree
Showing 124 changed files with 801 additions and 1,324 deletions.
4 changes: 1 addition & 3 deletions .eslintrc-browser.json
Expand Up @@ -15,9 +15,7 @@
"env": {},

"globals": {
"window": true,
"define": true,
"module": true
"window": true
},

"rules": {
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc-node.json
Expand Up @@ -4,7 +4,7 @@
"extends": "jquery",

"parserOptions": {
"ecmaVersion": 2017
"ecmaVersion": 2018
},

"env": {
Expand Down
11 changes: 10 additions & 1 deletion .eslintrc.json
@@ -1,5 +1,14 @@
{
"root": true,

"extends": "./.eslintrc-node.json"
"extends": "./.eslintrc-node.json",

"overrides": [
{
"files": "rollup.config.js",
"parserOptions": {
"sourceType": "module"
}
}
]
}
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -129,14 +129,14 @@ Rather than rebuilding jQuery with `grunt` every time you make a change, you can
$ grunt watch
```

Alternatively, you can **load tests in AMD** to avoid the need for rebuilding altogether.
Alternatively, you can **load tests as ECMAScript modules** to avoid the need for rebuilding altogether.

Click "Load with AMD" after loading the test page.
Click "Load as modules" after loading the test page.


### Repo organization

The jQuery source is organized with AMD modules and then concatenated and compiled at build time.
The jQuery source is organized with ECMAScript modules and then compiled into one file at build time.

jQuery also contains some special modules we call "var modules", which are placed in folders named "var". At build time, these small modules are compiled to simple var statements. This makes it easy for us to share variables across modules. Browse the "src" folder for examples.

Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Expand Up @@ -177,7 +177,7 @@ module.exports = function( grunt ) {
"test/unit/ready.js",

{ pattern: "dist/jquery.*", included: false, served: true },
{ pattern: "src/**", included: false, served: true },
{ pattern: "src/**", type: "module", included: false, served: true },
{ pattern: "node_modules/**", included: false, served: true },
{
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
Expand Down

0 comments on commit d0ce00c

Please sign in to comment.