Skip to content

Commit

Permalink
Add IIFE script version to dist
Browse files Browse the repository at this point in the history
  • Loading branch information
philipwalton committed Jun 2, 2021
1 parent e20501c commit e83a090
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The recommended way to use the `web-vitals` package is to install it from npm an

The following examples show how to load `web-vitals` from [unpkg.com](https://unpkg.com), whether your targeting just Chromium-based browsers (using the "standard" version) or additional browsers (using the "base+polyfill" version):

**Load the "standard" version** (using a module script)
**Load the "standard" version** _(using a module script)_

```html
<!-- Append the `?module` param to load the module version of `web-vitals` -->
Expand All @@ -132,7 +132,7 @@ The following examples show how to load `web-vitals` from [unpkg.com](https://un
<script>
(function() {
var script = document.createElement('script');
script.src = 'https://unpkg.com/web-vitals';
script.src = 'https://unpkg.com/web-vitals/dist/web-vitals.iife.js';
script.onload = function() {
// When loading `web-vitals` using a classic script, all the public
// methods can be found on the `webVitals` global namespace.
Expand Down Expand Up @@ -161,7 +161,7 @@ The following examples show how to load `web-vitals` from [unpkg.com](https://un
<script>
(function() {
var script = document.createElement('script');
script.src = 'https://unpkg.com/web-vitals';
script.src = 'https://unpkg.com/web-vitals/dist/web-vitals.iife.js';
script.onload = function() {
// When loading `web-vitals` using a classic script, all the public
// methods can be found on the `webVitals` global namespace.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test": "npm-run-all build -p -r test:*",
"test:e2e": "wdio wdio.conf.js",
"test:server": "node test/server.js",
"start": "run-p watch test:server",
"start": "run-s build:ts test:server watch",
"watch": "run-p watch:*",
"watch:ts": "tsc -b -w",
"watch:js": "rollup -c -w",
Expand Down
24 changes: 23 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const configurePlugins = ({module, polyfill = false}) => {
compress: true,
}),
replace({
'self.__WEB_VITALS_POLYFILL__': polyfill,
values: {
'self.__WEB_VITALS_POLYFILL__': polyfill,
},
preventAssignment: true,
})
]
}
Expand All @@ -55,6 +58,15 @@ const configs = [
},
plugins: configurePlugins({module: false, polyfill: false}),
},
{
input: 'dist/modules/index.js',
output: {
format: 'iife',
file: './dist/web-vitals.iife.js',
name: 'webVitals',
},
plugins: configurePlugins({module: false, polyfill: false}),
},
{
input: 'dist/modules/index.js',
output: {
Expand All @@ -73,6 +85,16 @@ const configs = [
},
plugins: configurePlugins({module: false, polyfill: true}),
},
{
input: 'dist/modules/index.js',
output: {
format: 'iife',
file: `./dist/web-vitals.base.iife.js`,
name: 'webVitals',
extend: true,
},
plugins: configurePlugins({module: false, polyfill: true}),
},
{
input: 'dist/modules/polyfill.js',
output: {
Expand Down

0 comments on commit e83a090

Please sign in to comment.