diff --git a/.eslintignore b/.eslintignore index c0cc587c..512998e0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,4 @@ /coverage /third_party /public/js/gulliver.js +/public/js/lighthouse-chart.js diff --git a/.gitignore b/.gitignore index 68b02ae0..b6490ace 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,7 @@ npm-debug.log key.json public/js/gulliver.js public/js/gulliver.js.map +public/js/lighthouse-chart.js +public/js/lighthouse-chart.js.map public/firebase-messaging-sw.js diff --git a/package.json b/package.json index 1d66ebbd..f2979205 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "private": true, "scripts": { "start": "node app.js", - "prestart": "rollup -c && npm run generate-msg-sw", + "prestart": "rollup -c rollup-config/gulliver.js && rollup -c rollup-config/lighthouse-chart.js && npm run generate-msg-sw", "monitor": "nodemon app.js", "deploy": "npm run prestart && gcloud app deploy app.yaml", "mocha": "_mocha test/**/*", diff --git a/public/js/lighthouse-chart.js b/public/js/lighthouse-chart.es6.js similarity index 95% rename from public/js/lighthouse-chart.js rename to public/js/lighthouse-chart.es6.js index 782fdf01..a50227bc 100644 --- a/public/js/lighthouse-chart.js +++ b/public/js/lighthouse-chart.es6.js @@ -15,6 +15,7 @@ /* global google */ /* eslint-env browser */ +import Loader from './loader'; /** * Use to make the API request to get the Lighthouse chart data for a PWA. @@ -25,7 +26,7 @@ class LighthouseChart { constructor() { this.chartElement = document.getElementById('chart'); - this.loader = new window.Loader(this.chartElement, 'dark-primary-background'); + this.loader = new Loader(this.chartElement, 'dark-primary-background'); } load() { @@ -66,7 +67,5 @@ class LighthouseChart { console.error('There was an error drawing the chart!', err); }); } - } - new LighthouseChart().load(); diff --git a/public/js/loader.js b/public/js/loader.js index 850836b1..a44d6390 100644 --- a/public/js/loader.js +++ b/public/js/loader.js @@ -71,8 +71,4 @@ class Loader { } } - -// HACK: attach loader class to window object so that chart.js (which is not -// managed by rollup) can use the loader. -window.Loader = Loader; export default Loader; diff --git a/rollup.config.js b/rollup-config/gulliver.js similarity index 100% rename from rollup.config.js rename to rollup-config/gulliver.js diff --git a/rollup-config/lighthouse-chart.js b/rollup-config/lighthouse-chart.js new file mode 100644 index 00000000..51792de2 --- /dev/null +++ b/rollup-config/lighthouse-chart.js @@ -0,0 +1,26 @@ +import babel from 'rollup-plugin-babel'; +import uglify from 'rollup-plugin-uglify'; +import nodeResolve from 'rollup-plugin-node-resolve'; +import commonsjs from 'rollup-plugin-commonjs'; + +export default { + entry: './public/js/lighthouse-chart.es6.js', + plugins: [ + babel({exclude: 'node_modules/**'}), + uglify(), + nodeResolve(), + commonsjs() + ], + // Quiet warning: https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined + context: 'window', + targets: [ + { + dest: './public/js/lighthouse-chart.js', + // Fixes 'navigator' not defined when using Firebase and strict mode: + // http://stackoverflow.com/questions/31221357/webpack-firebase-disable-parsing-of-firebase + useStrict: false, + format: 'iife', + sourceMap: true + } + ] +};