Skip to content

Commit

Permalink
Make ES modules option consistent (#1188)
Browse files Browse the repository at this point in the history
* Make ES modules option consistent

* Fix config in spec test

* Change tests to test both ESM and non-ESM
  • Loading branch information
schlessera authored Apr 1, 2021
1 parent 082fd32 commit 3ec7bd4
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 27 deletions.
16 changes: 0 additions & 16 deletions packages/optimizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,6 @@ Specifies the AMP format of the input file. Defaults to `AMP`.
- default: `AMP`
- used by: [AutoExtensionImport](lib/transformers/AutoExtensionImporter.js), [AddMandatoryTags](lib/transformers/AddMandatoryTags.js)

#### `experimentEsm`

Enable [JavaScript Module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) support for AMP runtime and components. AMP Optimizer will generate module/nonmodule script imports for AMP runtime and components:

```
<script async nomodule src="https://cdn.ampproject.org/v0.js"></script>
<script async src="https://cdn.ampproject.org/v0.mjs" type="module" crossorigin="anonymous"></script>
```

**Warning: this will result in invalid AMP pages.**

- name: `experimentEsm`
- valid options: `[true|false]`
- default: `false`
- used by: [RewriteAmpUrls](lib/transformers/RewriteAmpUrls.js)

#### `imageBasePath`

Specifies a base path used to resolve an image during build,
Expand Down
3 changes: 3 additions & 0 deletions packages/optimizer/lib/transformers/RewriteAmpUrls.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const {calculateHost} = require('../RuntimeHostHelper');
* option is ineffective with the lts flag, but will simply be ignored
* rather than throwing an error.
*
* * `esmModulesEnabled`: Enables the smaller ESM module version of AMP runtime
* and components.
*
* All parameters are optional. If no option is provided, runtime URLs won't be
* re-written. You can combine `ampRuntimeVersion` and `ampUrlPrefix` to
* rewrite AMP runtime URLs to versioned URLs on a different origin.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"experimentEsm": true
"esmModulesEnabled": true
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
{
"esmModulesEnabled": true
}
-->
<!doctype html>
<html >
<head>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<!doctype html>
<html >
<head>
<script async nomodule src="https://cdn.ampproject.org/lts/v0/amp-experiment-0.1.js" custom-element="amp-experiment"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/lts/v0/amp-experiment-0.1.mjs" type="module" crossorigin="anonymous"></script>
<script async nomodule src="https://cdn.ampproject.org/lts/v0.js"></script>
<script async src="https://cdn.ampproject.org/lts/v0.mjs" type="module" crossorigin="anonymous"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/lts/v0/amp-experiment-0.1.js"></script>
<script async src="https://cdn.ampproject.org/lts/v0.js"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/lts/v0.css">
<link href="https://fonts.googleapis.com/css?foobar" rel="stylesheet" type="text/css">
<link href="https://example.com/favicon.ico" rel="icon">
<link as="script" crossorigin="anonymous" href="https://cdn.ampproject.org/lts/v0.mjs" rel="modulepreload">
<link rel="preload" href="https://cdn.ampproject.org/lts/v0.js" as="script">
<link rel="preload" href="https://cdn.ampproject.org/lts/v0.css" as="style">
</head>
<body></body>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<!doctype html>
<html >
<head>
<script async nomodule src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js" custom-element="amp-experiment"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.mjs" type="module" crossorigin="anonymous"></script>
<script async nomodule src="https://cdn.ampproject.org/v0.js"></script>
<script async src="https://cdn.ampproject.org/v0.mjs" type="module" crossorigin="anonymous"></script>
<script async custom-element="amp-experiment" src="https://cdn.ampproject.org/v0/amp-experiment-0.1.js"></script>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<link rel="stylesheet" href="https://cdn.ampproject.org/v0.css">
<link href="https://fonts.googleapis.com/css?foobar" rel="stylesheet" type="text/css">
<link href="https://example.com/favicon.ico" rel="icon">
<link as="script" crossorigin="anonymous" href="https://cdn.ampproject.org/v0.mjs" rel="modulepreload">
<link rel="preload" href="https://cdn.ampproject.org/v0.js" as="script">
<link rel="preload" href="https://cdn.ampproject.org/v0.css" as="style">
</head>
<body></body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"esmModulesEnabled": false
}

0 comments on commit 3ec7bd4

Please sign in to comment.