From 6554fb800b0c0c4f3f8e3298b61f8f394e0f466a Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Wed, 29 Dec 2021 09:27:23 +0000 Subject: [PATCH 01/16] feat: add google analytics gtag.js plugin --- src/plugins/gtag.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/plugins/gtag.js diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js new file mode 100644 index 000000000..b1a8e5b18 --- /dev/null +++ b/src/plugins/gtag.js @@ -0,0 +1,43 @@ +/* eslint-disable no-console */ +// copy from ./ga.js +// usage is the same as ./ga.js +function appendScript(id) { + const script = document.createElement('script'); + script.async = true; + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; + document.body.appendChild(script); +} + +function init(id) { + appendScript(id); + + window.dataLayer = window.dataLayer || []; + window.gtag = window.gtag || function () { dataLayer.push(arguments); } + + gtag('js', new Date()); + gtag('config', id); +} + +function collect() { + if (!window.ga) { + init($docsify.ga); + } + + // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages + window.gtag('event', 'page_view', { + page_title: document.title, + page_location: location.href, + page_path: location.pathname + }) +} + +const install = function (hook) { + if (!$docsify.ga) { + console.error('[Docsify] ga is required.'); + return; + } + + hook.beforeEach(collect); +}; + +$docsify.plugins = [].concat(install, $docsify.plugins); From b3eeeedb6dae54d79249d3d9dc6930c917aab048 Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Tue, 4 Jan 2022 05:53:18 +0000 Subject: [PATCH 02/16] feat: add google universal analytics gtag.js plugin --- build/build.js | 1 + docs/plugins.md | 22 ++++++++++++++++++++++ src/plugins/gtag.js | 18 +++++++++++------- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/build/build.js b/build/build.js index 0de786828..91155512a 100644 --- a/build/build.js +++ b/build/build.js @@ -80,6 +80,7 @@ async function buildAllPlugin() { var plugins = [ {name: 'search', input: 'search/index.js'}, {name: 'ga', input: 'ga.js'}, + {name: 'gtag', input: 'gtag.js'}, {name: 'matomo', input: 'matomo.js'}, {name: 'emoji', input: 'emoji.js'}, {name: 'external-script', input: 'external-script.js'}, diff --git a/docs/plugins.md b/docs/plugins.md index b7ccb971f..811f66dbb 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -89,6 +89,28 @@ Configure by `data-ga`. ``` +## Google Universal Analytics (gtag.js) + +Usage is same as `Google Analytics`. + +```html + + + +``` + +Configure by `data-ga`. + +```html + + +``` + + ## emoji The default is to support parsing emoji. For example `:100:` will be parsed to :100:. But it is not precise because there is no matching non-emoji string. If you need to correctly parse the emoji string, you need install this plugin. diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js index b1a8e5b18..aa763fa86 100644 --- a/src/plugins/gtag.js +++ b/src/plugins/gtag.js @@ -12,10 +12,14 @@ function init(id) { appendScript(id); window.dataLayer = window.dataLayer || []; - window.gtag = window.gtag || function () { dataLayer.push(arguments); } - - gtag('js', new Date()); - gtag('config', id); + window.gtag = + window.gtag || + function() { + window.dataLayer.push(arguments); + }; + + window.gtag('js', new Date()); + window.gtag('config', id); } function collect() { @@ -27,11 +31,11 @@ function collect() { window.gtag('event', 'page_view', { page_title: document.title, page_location: location.href, - page_path: location.pathname - }) + page_path: location.pathname, + }); } -const install = function (hook) { +const install = function(hook) { if (!$docsify.ga) { console.error('[Docsify] ga is required.'); return; From 5a05b30ec3bae7fa7cb6c1a10d92f333b0bcabcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=94=81?= <52o@qq52o.cn> Date: Wed, 16 Mar 2022 07:58:47 +0800 Subject: [PATCH 03/16] Update gtag.js --- src/plugins/gtag.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js index aa763fa86..6fedda861 100644 --- a/src/plugins/gtag.js +++ b/src/plugins/gtag.js @@ -14,7 +14,7 @@ function init(id) { window.dataLayer = window.dataLayer || []; window.gtag = window.gtag || - function() { + function () { window.dataLayer.push(arguments); }; @@ -35,7 +35,7 @@ function collect() { }); } -const install = function(hook) { +const install = function (hook) { if (!$docsify.ga) { console.error('[Docsify] ga is required.'); return; From b3a8703ebe6a46f31ddff40ec9e3ad4ae938bfd1 Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Sun, 24 Apr 2022 23:04:34 +0800 Subject: [PATCH 04/16] feat: add google universal analytics gtag.js plugin --- build/build.js | 1 - docs/plugins.md | 31 +++++++++---------------- src/plugins/ga.js | 55 +++++++++++++++++++++++++++++++++++---------- src/plugins/gtag.js | 47 -------------------------------------- 4 files changed, 53 insertions(+), 81 deletions(-) delete mode 100644 src/plugins/gtag.js diff --git a/build/build.js b/build/build.js index 91155512a..0de786828 100644 --- a/build/build.js +++ b/build/build.js @@ -80,7 +80,6 @@ async function buildAllPlugin() { var plugins = [ {name: 'search', input: 'search/index.js'}, {name: 'ga', input: 'ga.js'}, - {name: 'gtag', input: 'gtag.js'}, {name: 'matomo', input: 'matomo.js'}, {name: 'emoji', input: 'emoji.js'}, {name: 'external-script', input: 'external-script.js'}, diff --git a/docs/plugins.md b/docs/plugins.md index bdbeb88dd..0e60b1944 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -78,6 +78,16 @@ Install the plugin and configure the track id. window.$docsify = { ga: 'UA-XXXXX-Y', }; + + // or multi gtag + window.$docsify = { + ga: [ + 'G-XXXXXXXX', // Google Analytics 4 (GA4) + 'UA-XXXXXXXX', // Google Universal Analytics (GA3) + 'AW-XXXXXXXX', // Google Ads + 'DC-XXXXXXXX' // Floodlight + ], + }; @@ -91,27 +101,6 @@ Configure by `data-ga`. ``` -## Google Universal Analytics (gtag.js) - -Usage is same as `Google Analytics`. - -```html - - - -``` - -Configure by `data-ga`. - -```html - - -``` - ## Emoji Renders a larger collection of emoji shorthand codes. Without this plugin, Docsify is able to render only a limited number of emoji shorthand codes. diff --git a/src/plugins/ga.js b/src/plugins/ga.js index 37167a4dc..4b24a24d8 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -1,22 +1,49 @@ /* eslint-disable no-console */ // From https://github.com/egoist/vue-ga/blob/master/src/index.js -function appendScript() { + +function appendScript(id) { const script = document.createElement('script'); script.async = true; - script.src = 'https://www.google-analytics.com/analytics.js'; + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; document.body.appendChild(script); } -function init(id) { - appendScript(); - window.ga = - window.ga || +// global site tag instance initialized +function initGlobalSiteTag(id){ + appendScript(id); + + window.dataLayer = window.dataLayer || []; + window.gtag = + window.gtag || function () { - (window.ga.q = window.ga.q || []).push(arguments); + window.dataLayer.push(arguments); }; - window.ga.l = Number(new Date()); - window.ga('create', id, 'auto'); + window.gtag('js', new Date()); + window.gtag('config', id); +} + +// add additional products to your tag +// https://developers.google.com/tag-platform/gtagjs/install +function initAdditionalTag(id){ + window.gtag('config', id); +} + +function init(ids) { + if (Array.isArray(ids)){ + + // the first id must be a global site tag id + initGlobalSiteTag(ids[0]); + + // the rest ids + ids.forEach((id, index)=>{ + if (index > 0){ + initAdditionalTag(id); + } + }) + } else { + initGlobalSiteTag(ids); + } } function collect() { @@ -24,8 +51,12 @@ function collect() { init($docsify.ga); } - window.ga('set', 'page', location.hash); - window.ga('send', 'pageview'); + // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages + window.gtag('event', 'page_view', { + page_title: document.title, + page_location: location.href, + page_path: location.pathname, + }); } const install = function (hook) { @@ -37,4 +68,4 @@ const install = function (hook) { hook.beforeEach(collect); }; -$docsify.plugins = [].concat(install, $docsify.plugins); +$docsify.plugins = [].concat(install, $docsify.plugins); \ No newline at end of file diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js deleted file mode 100644 index 6fedda861..000000000 --- a/src/plugins/gtag.js +++ /dev/null @@ -1,47 +0,0 @@ -/* eslint-disable no-console */ -// copy from ./ga.js -// usage is the same as ./ga.js -function appendScript(id) { - const script = document.createElement('script'); - script.async = true; - script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; - document.body.appendChild(script); -} - -function init(id) { - appendScript(id); - - window.dataLayer = window.dataLayer || []; - window.gtag = - window.gtag || - function () { - window.dataLayer.push(arguments); - }; - - window.gtag('js', new Date()); - window.gtag('config', id); -} - -function collect() { - if (!window.ga) { - init($docsify.ga); - } - - // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages - window.gtag('event', 'page_view', { - page_title: document.title, - page_location: location.href, - page_path: location.pathname, - }); -} - -const install = function (hook) { - if (!$docsify.ga) { - console.error('[Docsify] ga is required.'); - return; - } - - hook.beforeEach(collect); -}; - -$docsify.plugins = [].concat(install, $docsify.plugins); From 9e43564ba100ccc6703a9b39619f28949171afc4 Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Mon, 25 Apr 2022 12:06:42 +0800 Subject: [PATCH 05/16] feat: add google universal analytics gtag.js plugin --- docs/plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/plugins.md b/docs/plugins.md index 0e60b1944..d8c81c769 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -79,7 +79,7 @@ Install the plugin and configure the track id. ga: 'UA-XXXXX-Y', }; - // or multi gtag + // or multi gtag, the first element of the array must be a global site gtag id, each page should have only one global site tag instance. window.$docsify = { ga: [ 'G-XXXXXXXX', // Google Analytics 4 (GA4) From c97b35bb53322ea18d1470f127073270c4f40902 Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Tue, 24 May 2022 21:54:48 +0800 Subject: [PATCH 06/16] feat: add google universal analytics gtag.js plugin --- docs/plugins.md | 8 ++++---- src/plugins/ga.js | 33 ++++++++++++++++++++++----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index d8c81c769..857243794 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -78,14 +78,14 @@ Install the plugin and configure the track id. window.$docsify = { ga: 'UA-XXXXX-Y', }; - - // or multi gtag, the first element of the array must be a global site gtag id, each page should have only one global site tag instance. + + // or multi gtag, first tag at the beginning of G- from the array is global site gtag, each page should have only one global site tag instance. window.$docsify = { ga: [ 'G-XXXXXXXX', // Google Analytics 4 (GA4) 'UA-XXXXXXXX', // Google Universal Analytics (GA3) 'AW-XXXXXXXX', // Google Ads - 'DC-XXXXXXXX' // Floodlight + 'DC-XXXXXXXX', // Floodlight ], }; @@ -93,7 +93,7 @@ Install the plugin and configure the track id. ``` -Configure by `data-ga`. +Configure by `data-ga`, only support single gtag. ```html diff --git a/src/plugins/ga.js b/src/plugins/ga.js index 4b24a24d8..5635cb58d 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -1,6 +1,9 @@ /* eslint-disable no-console */ // From https://github.com/egoist/vue-ga/blob/master/src/index.js +// prefix of global site tag +const GLOBAL_SITE_TAG_PREFIX = 'G-'; + function appendScript(id) { const script = document.createElement('script'); script.async = true; @@ -9,7 +12,7 @@ function appendScript(id) { } // global site tag instance initialized -function initGlobalSiteTag(id){ +function initGlobalSiteTag(id) { appendScript(id); window.dataLayer = window.dataLayer || []; @@ -25,22 +28,30 @@ function initGlobalSiteTag(id){ // add additional products to your tag // https://developers.google.com/tag-platform/gtagjs/install -function initAdditionalTag(id){ +function initAdditionalTag(id) { window.gtag('config', id); } function init(ids) { - if (Array.isArray(ids)){ - - // the first id must be a global site tag id - initGlobalSiteTag(ids[0]); + if (Array.isArray(ids)) { + // default get the first id + let globalSiteTag = ids[0]; + let globalSiteTagArr = ids.filter( + id => id.indexOf(GLOBAL_SITE_TAG_PREFIX) === 0 + ); + if (globalSiteTagArr.length !== 0) { + globalSiteTag = globalSiteTagArr[0]; + } + + // initialized global site tag id + initGlobalSiteTag(globalSiteTag); // the rest ids - ids.forEach((id, index)=>{ - if (index > 0){ + ids + .filter(id => id !== globalSiteTag) + .forEach((id, index) => { initAdditionalTag(id); - } - }) + }); } else { initGlobalSiteTag(ids); } @@ -68,4 +79,4 @@ const install = function (hook) { hook.beforeEach(collect); }; -$docsify.plugins = [].concat(install, $docsify.plugins); \ No newline at end of file +$docsify.plugins = [].concat(install, $docsify.plugins); From 34105800669dd86b97512d587c23315cf725bcaa Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Wed, 25 May 2022 19:29:33 +0800 Subject: [PATCH 07/16] feat: add google universal analytics gtag.js plugin --- test/e2e/ga.test.js | 96 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 test/e2e/ga.test.js diff --git a/test/e2e/ga.test.js b/test/e2e/ga.test.js new file mode 100644 index 000000000..c54716123 --- /dev/null +++ b/test/e2e/ga.test.js @@ -0,0 +1,96 @@ +// Modules, constants, and variables +// ----------------------------------------------------------------------------- +const docsifyInit = require('../helpers/docsify-init'); +const { test, expect } = require('./fixtures/docsify-init-fixture'); + +const gaTagList = [ + 'AW-YYYYYY', // Google Ads + 'DC-ZZZZZZ', // Floodlight + 'G-XXXXXX', // Google Analytics 4 (GA4) + 'UA-XXXXXX', // Google Universal Analytics (GA3) +]; + +// Suite +// ----------------------------------------------------------------------------- +test.describe('GA Plugin Tests', () => { + // page request listened, print collect url + function pageRequestListened(page) { + // page.on('request', request => { + // if (request.url().indexOf('www.google-analytics.com') !== -1) { + // console.log(request.url()); + // } + // }); + + page.on('response', response => { + const request = response.request(); + // googleads.g.doubleclick.net + // www.google-analytics.com + // www.googletagmanager.com + const reg = + /googleads\.g\.doubleclick\.net|www\.google-analytics\.com|www\.googletagmanager\.com/g; + if (request.url().match(reg)) { + console.log(request.url(), response.status()); + } + }); + } + + // Tests + // --------------------------------------------------------------------------- + test('single gtag', async ({ page }) => { + pageRequestListened(page); + + const docsifyInitConfig = { + config: { + ga: gaTagList[0], + }, + scriptURLs: ['/lib/plugins/ga.min.js'], + styleURLs: ['/lib/themes/vue.css'], + }; + + await docsifyInit({ + ...docsifyInitConfig, + }); + + const $docsify = await page.evaluate(() => window.$docsify); + + // Verify config options + expect(typeof $docsify).toEqual('object'); + + console.log($docsify.ga, $docsify.ga === ''); + + // Tests + expect($docsify.ga).not.toEqual(''); + }); + + test('multi gtag', async ({ page }) => { + pageRequestListened(page); + + const docsifyInitConfig = { + config: { + ga: gaTagList, + }, + scriptURLs: ['/lib/plugins/ga.min.js'], + styleURLs: ['/lib/themes/vue.css'], + }; + + await docsifyInit({ + ...docsifyInitConfig, + }); + + const $docsify = await page.evaluate(() => window.$docsify); + + // Verify config options + expect(typeof $docsify).toEqual('object'); + + console.log($docsify.ga, $docsify.ga === ''); + + // Tests + expect($docsify.ga).not.toEqual(''); + }); + + test('data-ga attribute', async ({ page }) => { + pageRequestListened(page); + + // TODO + }); +}); From 456f844d4778e05dadee5f4f41827ecd9ccc5a3c Mon Sep 17 00:00:00 2001 From: Eko Zhan Date: Thu, 2 Jun 2022 13:03:26 +0800 Subject: [PATCH 08/16] feat: add google universal analytics gtag.js plugin --- docs/plugins.md | 3 ++- src/plugins/ga.js | 24 ++++++------------------ test/e2e/ga.test.js | 1 + 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/docs/plugins.md b/docs/plugins.md index 857243794..1c538d049 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -75,11 +75,12 @@ Install the plugin and configure the track id. ```html + + +``` + +Configure by `data-ga`. + + +```html + + +``` + +## Google Analytics 4 (GA4) + +Install the plugin and configure the track id. + +```html + - -``` - -Configure by `data-ga`, only support single gtag. - - -```html - - + ``` ## Emoji diff --git a/src/plugins/ga.js b/src/plugins/ga.js index 8f0e42e22..37167a4dc 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -1,48 +1,22 @@ /* eslint-disable no-console */ // From https://github.com/egoist/vue-ga/blob/master/src/index.js - -function appendScript(id) { +function appendScript() { const script = document.createElement('script'); script.async = true; - script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; + script.src = 'https://www.google-analytics.com/analytics.js'; document.body.appendChild(script); } -// global site tag instance initialized -function initGlobalSiteTag(id) { - appendScript(id); - - window.dataLayer = window.dataLayer || []; - window.gtag = - window.gtag || +function init(id) { + appendScript(); + window.ga = + window.ga || function () { - window.dataLayer.push(arguments); + (window.ga.q = window.ga.q || []).push(arguments); }; - window.gtag('js', new Date()); - window.gtag('config', id); -} - -// add additional products to your tag -// https://developers.google.com/tag-platform/gtagjs/install -function initAdditionalTag(id) { - window.gtag('config', id); -} - -function init(ids) { - if (Array.isArray(ids)) { - // set the first id to be a global site tag - initGlobalSiteTag(ids[0]); - - // the rest ids - ids.forEach((id, index) => { - if (index > 0) { - initAdditionalTag(id); - } - }); - } else { - initGlobalSiteTag(ids); - } + window.ga.l = Number(new Date()); + window.ga('create', id, 'auto'); } function collect() { @@ -50,12 +24,8 @@ function collect() { init($docsify.ga); } - // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages - window.gtag('event', 'page_view', { - page_title: document.title, - page_location: location.href, - page_path: location.pathname, - }); + window.ga('set', 'page', location.hash); + window.ga('send', 'pageview'); } const install = function (hook) { diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js new file mode 100644 index 000000000..aec713cb7 --- /dev/null +++ b/src/plugins/gtag.js @@ -0,0 +1,72 @@ +/* eslint-disable no-console */ +// From ./ga.js + +function appendScript(id) { + const script = document.createElement('script'); + script.async = true; + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; + document.body.appendChild(script); +} + +// global site tag instance initialized +function initGlobalSiteTag(id) { + appendScript(id); + + window.dataLayer = window.dataLayer || []; + window.gtag = + window.gtag || + function () { + window.dataLayer.push(arguments); + }; + + window.gtag('js', new Date()); + window.gtag('config', id); +} + +// add additional products to your tag +// https://developers.google.com/tag-platform/gtagjs/install +function initAdditionalTag(id) { + window.gtag('config', id); +} + +function init(ids) { + if (Array.isArray(ids)) { + // set the first id to be a global site tag + initGlobalSiteTag(ids[0]); + + // the rest ids + ids.forEach((id, index) => { + if (index > 0) { + initAdditionalTag(id); + } + }); + } else { + initGlobalSiteTag(ids); + } +} + +function collect() { + if (!window.gtag) { + init($docsify.gtag); + } + + // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages + window.gtag('event', 'page_view', { + /* eslint-disable camelcase */ + page_title: document.title, + page_location: location.href, + page_path: location.pathname, + /* eslint-disable camelcase */ + }); +} + +const install = function (hook) { + if (!$docsify.gtag) { + console.error('[Docsify] gtag is required.'); + return; + } + + hook.beforeEach(collect); +}; + +$docsify.plugins = [].concat(install, $docsify.plugins); diff --git a/test/e2e/ga.test.js b/test/e2e/gtag.test.js similarity index 74% rename from test/e2e/ga.test.js rename to test/e2e/gtag.test.js index c021eaa9f..c3ebbcd18 100644 --- a/test/e2e/ga.test.js +++ b/test/e2e/gtag.test.js @@ -1,10 +1,10 @@ // Modules, constants, and variables -// npm run test:e2e ga.test.js +// npm run test:e2e gtag.test.js // ----------------------------------------------------------------------------- const docsifyInit = require('../helpers/docsify-init'); const { test, expect } = require('./fixtures/docsify-init-fixture'); -const gaTagList = [ +const gtagList = [ 'AW-YYYYYY', // Google Ads 'DC-ZZZZZZ', // Floodlight 'G-XXXXXX', // Google Analytics 4 (GA4) @@ -13,14 +13,14 @@ const gaTagList = [ // Suite // ----------------------------------------------------------------------------- -test.describe('GA Plugin Tests', () => { +test.describe('Gtag Plugin Tests', () => { // page request listened, print collect url function pageRequestListened(page) { - // page.on('request', request => { - // if (request.url().indexOf('www.google-analytics.com') !== -1) { - // console.log(request.url()); - // } - // }); + page.on('request', request => { + if (request.url().indexOf('www.google-analytics.com') !== -1) { + // console.log(request.url()); + } + }); page.on('response', response => { const request = response.request(); @@ -30,7 +30,7 @@ test.describe('GA Plugin Tests', () => { const reg = /googleads\.g\.doubleclick\.net|www\.google-analytics\.com|www\.googletagmanager\.com/g; if (request.url().match(reg)) { - console.log(request.url(), response.status()); + // console.log(request.url(), response.status()); } }); } @@ -42,9 +42,9 @@ test.describe('GA Plugin Tests', () => { const docsifyInitConfig = { config: { - ga: gaTagList[0], + gtag: gtagList[0], }, - scriptURLs: ['/lib/plugins/ga.min.js'], + scriptURLs: ['/lib/plugins/gtag.min.js'], styleURLs: ['/lib/themes/vue.css'], }; @@ -57,10 +57,10 @@ test.describe('GA Plugin Tests', () => { // Verify config options expect(typeof $docsify).toEqual('object'); - console.log($docsify.ga, $docsify.ga === ''); + // console.log($docsify.gtag, $docsify.gtag === ''); // Tests - expect($docsify.ga).not.toEqual(''); + expect($docsify.gtag).not.toEqual(''); }); test('multi gtag', async ({ page }) => { @@ -68,9 +68,9 @@ test.describe('GA Plugin Tests', () => { const docsifyInitConfig = { config: { - ga: gaTagList, + gtag: gtagList, }, - scriptURLs: ['/lib/plugins/ga.min.js'], + scriptURLs: ['/lib/plugins/gtag.min.js'], styleURLs: ['/lib/themes/vue.css'], }; @@ -83,10 +83,10 @@ test.describe('GA Plugin Tests', () => { // Verify config options expect(typeof $docsify).toEqual('object'); - console.log($docsify.ga, $docsify.ga === ''); + // console.log($docsify.gtag, $docsify.gtag === ''); // Tests - expect($docsify.ga).not.toEqual(''); + expect($docsify.gtag).not.toEqual(''); }); test('data-ga attribute', async ({ page }) => { From 634b94837be499d8668f701d59a75888a9177706 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:10:07 -0500 Subject: [PATCH 10/16] test: Disable uglify --- build/build.js | 161 +++++++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 79 deletions(-) diff --git a/build/build.js b/build/build.js index 91155512a..8523da14c 100644 --- a/build/build.js +++ b/build/build.js @@ -1,13 +1,13 @@ -const rollup = require('rollup') -const buble = require('rollup-plugin-buble') -const commonjs = require('rollup-plugin-commonjs') -const nodeResolve = require('rollup-plugin-node-resolve') -const { uglify } = require('rollup-plugin-uglify') -const replace = require('rollup-plugin-replace') -const isProd = process.env.NODE_ENV === 'production' -const version = process.env.VERSION || require('../package.json').version -const chokidar = require('chokidar') -const path = require('path') +const rollup = require('rollup'); +const buble = require('rollup-plugin-buble'); +const commonjs = require('rollup-plugin-commonjs'); +const nodeResolve = require('rollup-plugin-node-resolve'); +const { uglify } = require('rollup-plugin-uglify'); +const replace = require('rollup-plugin-replace'); +const isProd = process.env.NODE_ENV === 'production'; +const version = process.env.VERSION || require('../package.json').version; +const chokidar = require('chokidar'); +const path = require('path'); /** * @param {{ @@ -24,90 +24,97 @@ async function build(opts) { plugins: (opts.plugins || []).concat([ buble({ transforms: { - dangerousForOf: true - }}), + dangerousForOf: true, + }, + }), commonjs(), nodeResolve(), replace({ __VERSION__: version, - 'process.env.SSR': false - }) + 'process.env.SSR': false, + }), ]), onwarn: function (message) { if (message.code === 'UNRESOLVED_IMPORT') { throw new Error( `Could not resolve module ` + - message.source + - `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` + - `Module ${message.source} is imported in ${message.importer}` - ) + message.source + + `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` + + `Module ${message.source} is imported in ${message.importer}` + ); } - } + }, }) .then(function (bundle) { - var dest = 'lib/' + (opts.output || opts.input) + var dest = 'lib/' + (opts.output || opts.input); - console.log(dest) + console.log(dest); return bundle.write({ format: 'iife', - output: opts.globalName ? {name: opts.globalName} : {}, + output: opts.globalName ? { name: opts.globalName } : {}, file: dest, - strict: false - }) - }) + strict: false, + }); + }); } async function buildCore() { - const promises = [] + const promises = []; - promises.push(build({ - input: 'src/core/index.js', - output: 'docsify.js', - })) + promises.push( + build({ + input: 'src/core/index.js', + output: 'docsify.js', + }) + ); if (isProd) { - promises.push(build({ - input: 'src/core/index.js', - output: 'docsify.min.js', - plugins: [uglify()] - })) + promises.push( + build({ + input: 'src/core/index.js', + output: 'docsify.min.js', + // plugins: [uglify()] + }) + ); } - await Promise.all(promises) + await Promise.all(promises); } async function buildAllPlugin() { var plugins = [ - {name: 'search', input: 'search/index.js'}, - {name: 'ga', input: 'ga.js'}, - {name: 'gtag', input: 'gtag.js'}, - {name: 'matomo', input: 'matomo.js'}, - {name: 'emoji', input: 'emoji.js'}, - {name: 'external-script', input: 'external-script.js'}, - {name: 'front-matter', input: 'front-matter/index.js'}, - {name: 'zoom-image', input: 'zoom-image.js'}, - {name: 'disqus', input: 'disqus.js'}, - {name: 'gitalk', input: 'gitalk.js'} - ] + { name: 'search', input: 'search/index.js' }, + { name: 'ga', input: 'ga.js' }, + { name: 'gtag', input: 'gtag.js' }, + { name: 'matomo', input: 'matomo.js' }, + { name: 'emoji', input: 'emoji.js' }, + { name: 'external-script', input: 'external-script.js' }, + { name: 'front-matter', input: 'front-matter/index.js' }, + { name: 'zoom-image', input: 'zoom-image.js' }, + { name: 'disqus', input: 'disqus.js' }, + { name: 'gitalk', input: 'gitalk.js' }, + ]; const promises = plugins.map(item => { return build({ input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.js' - }) - }) + output: 'plugins/' + item.name + '.js', + }); + }); if (isProd) { plugins.forEach(item => { - promises.push(build({ - input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.min.js', - plugins: [uglify()] - })) - }) + promises.push( + build({ + input: 'src/plugins/' + item.input, + output: 'plugins/' + item.name + '.min.js', + // plugins: [uglify()] + }) + ); + }); } - await Promise.all(promises) + await Promise.all(promises); } async function main() { @@ -117,41 +124,37 @@ async function main() { atomic: true, awaitWriteFinish: { stabilityThreshold: 1000, - pollInterval: 100 - } + pollInterval: 100, + }, }) .on('change', p => { - console.log('[watch] ', p) - const dirs = p.split(path.sep) + console.log('[watch] ', p); + const dirs = p.split(path.sep); if (dirs[1] === 'core') { - buildCore() + buildCore(); } else if (dirs[2]) { - const name = path.basename(dirs[2], '.js') + const name = path.basename(dirs[2], '.js'); const input = `src/plugins/${name}${ /\.js/.test(dirs[2]) ? '' : '/index' - }.js` + }.js`; build({ input, - output: 'plugins/' + name + '.js' - }) + output: 'plugins/' + name + '.js', + }); } }) .on('ready', () => { - console.log('[start]') - buildCore() - buildAllPlugin() - }) + console.log('[start]'); + buildCore(); + buildAllPlugin(); + }); } else { - await Promise.all([ - buildCore(), - buildAllPlugin() - ]) + await Promise.all([buildCore(), buildAllPlugin()]); } } -main().catch((e) => { - console.error(e) - process.exit(1) -}) - +main().catch(e => { + console.error(e); + process.exit(1); +}); From c399f3c8d7625778f00a2c77368e8c8a00326620 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:16:56 -0500 Subject: [PATCH 11/16] test: IIFE --- build/build.js | 4 +- src/plugins/gtag.js | 121 ++++++++++++++++++++++---------------------- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/build/build.js b/build/build.js index 8523da14c..1bd093e0e 100644 --- a/build/build.js +++ b/build/build.js @@ -73,7 +73,7 @@ async function buildCore() { build({ input: 'src/core/index.js', output: 'docsify.min.js', - // plugins: [uglify()] + plugins: [uglify()], }) ); } @@ -108,7 +108,7 @@ async function buildAllPlugin() { build({ input: 'src/plugins/' + item.input, output: 'plugins/' + item.name + '.min.js', - // plugins: [uglify()] + plugins: [uglify()], }) ); }); diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js index aec713cb7..c8adfe21e 100644 --- a/src/plugins/gtag.js +++ b/src/plugins/gtag.js @@ -1,72 +1,73 @@ -/* eslint-disable no-console */ -// From ./ga.js - -function appendScript(id) { - const script = document.createElement('script'); - script.async = true; - script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; - document.body.appendChild(script); -} - -// global site tag instance initialized -function initGlobalSiteTag(id) { - appendScript(id); - - window.dataLayer = window.dataLayer || []; - window.gtag = - window.gtag || - function () { - window.dataLayer.push(arguments); - }; +(function () { + function appendScript(id) { + const script = document.createElement('script'); + script.async = true; + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; + document.body.appendChild(script); + } - window.gtag('js', new Date()); - window.gtag('config', id); -} + // global site tag instance initialized + function initGlobalSiteTag(id) { + appendScript(id); -// add additional products to your tag -// https://developers.google.com/tag-platform/gtagjs/install -function initAdditionalTag(id) { - window.gtag('config', id); -} + window.dataLayer = window.dataLayer || []; + window.gtag = + window.gtag || + function () { + window.dataLayer.push(arguments); + }; -function init(ids) { - if (Array.isArray(ids)) { - // set the first id to be a global site tag - initGlobalSiteTag(ids[0]); + window.gtag('js', new Date()); + window.gtag('config', id); + } - // the rest ids - ids.forEach((id, index) => { - if (index > 0) { - initAdditionalTag(id); - } - }); - } else { - initGlobalSiteTag(ids); + // add additional products to your tag + // https://developers.google.com/tag-platform/gtagjs/install + function initAdditionalTag(id) { + window.gtag('config', id); } -} -function collect() { - if (!window.gtag) { - init($docsify.gtag); + function init(ids) { + if (Array.isArray(ids)) { + // set the first id to be a global site tag + initGlobalSiteTag(ids[0]); + + // the rest ids + ids.forEach((id, index) => { + if (index > 0) { + initAdditionalTag(id); + } + }); + } else { + initGlobalSiteTag(ids); + } } - // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages - window.gtag('event', 'page_view', { - /* eslint-disable camelcase */ - page_title: document.title, - page_location: location.href, - page_path: location.pathname, - /* eslint-disable camelcase */ - }); -} + function collect() { + if (!window.gtag) { + init($docsify.gtag); + } -const install = function (hook) { - if (!$docsify.gtag) { - console.error('[Docsify] gtag is required.'); - return; + // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages + window.gtag('event', 'page_view', { + /* eslint-disable camelcase */ + page_title: document.title, + page_location: location.href, + page_path: location.pathname, + /* eslint-disable camelcase */ + }); } + const gtagPlugin = function (hook, vm) { + if (!$docsify.gtag) { + /* eslint-disable-next-line no-console */ + console.error('[Docsify] gtag is required.'); + return; + } - hook.beforeEach(collect); -}; + hook.beforeEach(collect); + }; -$docsify.plugins = [].concat(install, $docsify.plugins); + // Add plugin to docsify's plugin array + $docsify = $docsify || {}; + $docsify.plugins = [].concat($docsify.plugins || [], gtagPlugin); +})(); From 449d00a783eae7416c80da38f9faf1cd8f385ad6 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:21:26 -0500 Subject: [PATCH 12/16] test: IIFE (ga & gtag) --- src/plugins/ga.js | 68 +++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/plugins/ga.js b/src/plugins/ga.js index 37167a4dc..b7b3cf132 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -1,40 +1,44 @@ -/* eslint-disable no-console */ -// From https://github.com/egoist/vue-ga/blob/master/src/index.js -function appendScript() { - const script = document.createElement('script'); - script.async = true; - script.src = 'https://www.google-analytics.com/analytics.js'; - document.body.appendChild(script); -} - -function init(id) { - appendScript(); - window.ga = - window.ga || - function () { - (window.ga.q = window.ga.q || []).push(arguments); - }; +(function () { + // From https://github.com/egoist/vue-ga/blob/master/src/index.js + function appendScript() { + const script = document.createElement('script'); + script.async = true; + script.src = 'https://www.google-analytics.com/analytics.js'; + document.body.appendChild(script); + } - window.ga.l = Number(new Date()); - window.ga('create', id, 'auto'); -} + function init(id) { + appendScript(); + window.ga = + window.ga || + function () { + (window.ga.q = window.ga.q || []).push(arguments); + }; -function collect() { - if (!window.ga) { - init($docsify.ga); + window.ga.l = Number(new Date()); + window.ga('create', id, 'auto'); } - window.ga('set', 'page', location.hash); - window.ga('send', 'pageview'); -} + function collect() { + if (!window.ga) { + init($docsify.ga); + } -const install = function (hook) { - if (!$docsify.ga) { - console.error('[Docsify] ga is required.'); - return; + window.ga('set', 'page', location.hash); + window.ga('send', 'pageview'); } - hook.beforeEach(collect); -}; + const gaPlugin = function (hook, vm) { + if (!$docsify.ga) { + /* eslint-disable-next-line no-console */ + console.error('[Docsify] ga is required.'); + return; + } + + hook.beforeEach(collect); + }; -$docsify.plugins = [].concat(install, $docsify.plugins); + // Add plugin to docsify's plugin array + $docsify = $docsify || {}; + $docsify.plugins = [].concat($docsify.plugins || [], gaPlugin); +})(); From 54a1131fca88fe9f6cc8dfb7bfc6c4c2f576bbb9 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:33:34 -0500 Subject: [PATCH 13/16] Revert "test: IIFE (ga & gtag)" This reverts commit 449d00a783eae7416c80da38f9faf1cd8f385ad6. --- src/plugins/ga.js | 68 ++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/plugins/ga.js b/src/plugins/ga.js index b7b3cf132..37167a4dc 100644 --- a/src/plugins/ga.js +++ b/src/plugins/ga.js @@ -1,44 +1,40 @@ -(function () { - // From https://github.com/egoist/vue-ga/blob/master/src/index.js - function appendScript() { - const script = document.createElement('script'); - script.async = true; - script.src = 'https://www.google-analytics.com/analytics.js'; - document.body.appendChild(script); - } +/* eslint-disable no-console */ +// From https://github.com/egoist/vue-ga/blob/master/src/index.js +function appendScript() { + const script = document.createElement('script'); + script.async = true; + script.src = 'https://www.google-analytics.com/analytics.js'; + document.body.appendChild(script); +} + +function init(id) { + appendScript(); + window.ga = + window.ga || + function () { + (window.ga.q = window.ga.q || []).push(arguments); + }; - function init(id) { - appendScript(); - window.ga = - window.ga || - function () { - (window.ga.q = window.ga.q || []).push(arguments); - }; + window.ga.l = Number(new Date()); + window.ga('create', id, 'auto'); +} - window.ga.l = Number(new Date()); - window.ga('create', id, 'auto'); +function collect() { + if (!window.ga) { + init($docsify.ga); } - function collect() { - if (!window.ga) { - init($docsify.ga); - } + window.ga('set', 'page', location.hash); + window.ga('send', 'pageview'); +} - window.ga('set', 'page', location.hash); - window.ga('send', 'pageview'); +const install = function (hook) { + if (!$docsify.ga) { + console.error('[Docsify] ga is required.'); + return; } - const gaPlugin = function (hook, vm) { - if (!$docsify.ga) { - /* eslint-disable-next-line no-console */ - console.error('[Docsify] ga is required.'); - return; - } - - hook.beforeEach(collect); - }; + hook.beforeEach(collect); +}; - // Add plugin to docsify's plugin array - $docsify = $docsify || {}; - $docsify.plugins = [].concat($docsify.plugins || [], gaPlugin); -})(); +$docsify.plugins = [].concat(install, $docsify.plugins); From 393e66a8c63a4c1773f593dd6fe73c803689f5ba Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:33:43 -0500 Subject: [PATCH 14/16] Revert "test: IIFE" This reverts commit c399f3c8d7625778f00a2c77368e8c8a00326620. --- build/build.js | 4 +- src/plugins/gtag.js | 121 ++++++++++++++++++++++---------------------- 2 files changed, 62 insertions(+), 63 deletions(-) diff --git a/build/build.js b/build/build.js index 1bd093e0e..8523da14c 100644 --- a/build/build.js +++ b/build/build.js @@ -73,7 +73,7 @@ async function buildCore() { build({ input: 'src/core/index.js', output: 'docsify.min.js', - plugins: [uglify()], + // plugins: [uglify()] }) ); } @@ -108,7 +108,7 @@ async function buildAllPlugin() { build({ input: 'src/plugins/' + item.input, output: 'plugins/' + item.name + '.min.js', - plugins: [uglify()], + // plugins: [uglify()] }) ); }); diff --git a/src/plugins/gtag.js b/src/plugins/gtag.js index c8adfe21e..aec713cb7 100644 --- a/src/plugins/gtag.js +++ b/src/plugins/gtag.js @@ -1,73 +1,72 @@ -(function () { - function appendScript(id) { - const script = document.createElement('script'); - script.async = true; - script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; - document.body.appendChild(script); - } +/* eslint-disable no-console */ +// From ./ga.js - // global site tag instance initialized - function initGlobalSiteTag(id) { - appendScript(id); +function appendScript(id) { + const script = document.createElement('script'); + script.async = true; + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; + document.body.appendChild(script); +} - window.dataLayer = window.dataLayer || []; - window.gtag = - window.gtag || - function () { - window.dataLayer.push(arguments); - }; +// global site tag instance initialized +function initGlobalSiteTag(id) { + appendScript(id); - window.gtag('js', new Date()); - window.gtag('config', id); - } + window.dataLayer = window.dataLayer || []; + window.gtag = + window.gtag || + function () { + window.dataLayer.push(arguments); + }; - // add additional products to your tag - // https://developers.google.com/tag-platform/gtagjs/install - function initAdditionalTag(id) { - window.gtag('config', id); - } + window.gtag('js', new Date()); + window.gtag('config', id); +} + +// add additional products to your tag +// https://developers.google.com/tag-platform/gtagjs/install +function initAdditionalTag(id) { + window.gtag('config', id); +} - function init(ids) { - if (Array.isArray(ids)) { - // set the first id to be a global site tag - initGlobalSiteTag(ids[0]); +function init(ids) { + if (Array.isArray(ids)) { + // set the first id to be a global site tag + initGlobalSiteTag(ids[0]); - // the rest ids - ids.forEach((id, index) => { - if (index > 0) { - initAdditionalTag(id); - } - }); - } else { - initGlobalSiteTag(ids); - } + // the rest ids + ids.forEach((id, index) => { + if (index > 0) { + initAdditionalTag(id); + } + }); + } else { + initGlobalSiteTag(ids); + } +} + +function collect() { + if (!window.gtag) { + init($docsify.gtag); } - function collect() { - if (!window.gtag) { - init($docsify.gtag); - } + // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages + window.gtag('event', 'page_view', { + /* eslint-disable camelcase */ + page_title: document.title, + page_location: location.href, + page_path: location.pathname, + /* eslint-disable camelcase */ + }); +} - // usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages - window.gtag('event', 'page_view', { - /* eslint-disable camelcase */ - page_title: document.title, - page_location: location.href, - page_path: location.pathname, - /* eslint-disable camelcase */ - }); +const install = function (hook) { + if (!$docsify.gtag) { + console.error('[Docsify] gtag is required.'); + return; } - const gtagPlugin = function (hook, vm) { - if (!$docsify.gtag) { - /* eslint-disable-next-line no-console */ - console.error('[Docsify] gtag is required.'); - return; - } - hook.beforeEach(collect); - }; + hook.beforeEach(collect); +}; - // Add plugin to docsify's plugin array - $docsify = $docsify || {}; - $docsify.plugins = [].concat($docsify.plugins || [], gtagPlugin); -})(); +$docsify.plugins = [].concat(install, $docsify.plugins); From 054a93e789f68790bca7b6c62e6b810ac8cc8b26 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:33:49 -0500 Subject: [PATCH 15/16] Revert "test: Disable uglify" This reverts commit 634b94837be499d8668f701d59a75888a9177706. --- build/build.js | 161 ++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 82 deletions(-) diff --git a/build/build.js b/build/build.js index 8523da14c..91155512a 100644 --- a/build/build.js +++ b/build/build.js @@ -1,13 +1,13 @@ -const rollup = require('rollup'); -const buble = require('rollup-plugin-buble'); -const commonjs = require('rollup-plugin-commonjs'); -const nodeResolve = require('rollup-plugin-node-resolve'); -const { uglify } = require('rollup-plugin-uglify'); -const replace = require('rollup-plugin-replace'); -const isProd = process.env.NODE_ENV === 'production'; -const version = process.env.VERSION || require('../package.json').version; -const chokidar = require('chokidar'); -const path = require('path'); +const rollup = require('rollup') +const buble = require('rollup-plugin-buble') +const commonjs = require('rollup-plugin-commonjs') +const nodeResolve = require('rollup-plugin-node-resolve') +const { uglify } = require('rollup-plugin-uglify') +const replace = require('rollup-plugin-replace') +const isProd = process.env.NODE_ENV === 'production' +const version = process.env.VERSION || require('../package.json').version +const chokidar = require('chokidar') +const path = require('path') /** * @param {{ @@ -24,97 +24,90 @@ async function build(opts) { plugins: (opts.plugins || []).concat([ buble({ transforms: { - dangerousForOf: true, - }, - }), + dangerousForOf: true + }}), commonjs(), nodeResolve(), replace({ __VERSION__: version, - 'process.env.SSR': false, - }), + 'process.env.SSR': false + }) ]), onwarn: function (message) { if (message.code === 'UNRESOLVED_IMPORT') { throw new Error( `Could not resolve module ` + - message.source + - `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` + - `Module ${message.source} is imported in ${message.importer}` - ); + message.source + + `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` + + `Module ${message.source} is imported in ${message.importer}` + ) } - }, + } }) .then(function (bundle) { - var dest = 'lib/' + (opts.output || opts.input); + var dest = 'lib/' + (opts.output || opts.input) - console.log(dest); + console.log(dest) return bundle.write({ format: 'iife', - output: opts.globalName ? { name: opts.globalName } : {}, + output: opts.globalName ? {name: opts.globalName} : {}, file: dest, - strict: false, - }); - }); + strict: false + }) + }) } async function buildCore() { - const promises = []; + const promises = [] - promises.push( - build({ - input: 'src/core/index.js', - output: 'docsify.js', - }) - ); + promises.push(build({ + input: 'src/core/index.js', + output: 'docsify.js', + })) if (isProd) { - promises.push( - build({ - input: 'src/core/index.js', - output: 'docsify.min.js', - // plugins: [uglify()] - }) - ); + promises.push(build({ + input: 'src/core/index.js', + output: 'docsify.min.js', + plugins: [uglify()] + })) } - await Promise.all(promises); + await Promise.all(promises) } async function buildAllPlugin() { var plugins = [ - { name: 'search', input: 'search/index.js' }, - { name: 'ga', input: 'ga.js' }, - { name: 'gtag', input: 'gtag.js' }, - { name: 'matomo', input: 'matomo.js' }, - { name: 'emoji', input: 'emoji.js' }, - { name: 'external-script', input: 'external-script.js' }, - { name: 'front-matter', input: 'front-matter/index.js' }, - { name: 'zoom-image', input: 'zoom-image.js' }, - { name: 'disqus', input: 'disqus.js' }, - { name: 'gitalk', input: 'gitalk.js' }, - ]; + {name: 'search', input: 'search/index.js'}, + {name: 'ga', input: 'ga.js'}, + {name: 'gtag', input: 'gtag.js'}, + {name: 'matomo', input: 'matomo.js'}, + {name: 'emoji', input: 'emoji.js'}, + {name: 'external-script', input: 'external-script.js'}, + {name: 'front-matter', input: 'front-matter/index.js'}, + {name: 'zoom-image', input: 'zoom-image.js'}, + {name: 'disqus', input: 'disqus.js'}, + {name: 'gitalk', input: 'gitalk.js'} + ] const promises = plugins.map(item => { return build({ input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.js', - }); - }); + output: 'plugins/' + item.name + '.js' + }) + }) if (isProd) { plugins.forEach(item => { - promises.push( - build({ - input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.min.js', - // plugins: [uglify()] - }) - ); - }); + promises.push(build({ + input: 'src/plugins/' + item.input, + output: 'plugins/' + item.name + '.min.js', + plugins: [uglify()] + })) + }) } - await Promise.all(promises); + await Promise.all(promises) } async function main() { @@ -124,37 +117,41 @@ async function main() { atomic: true, awaitWriteFinish: { stabilityThreshold: 1000, - pollInterval: 100, - }, + pollInterval: 100 + } }) .on('change', p => { - console.log('[watch] ', p); - const dirs = p.split(path.sep); + console.log('[watch] ', p) + const dirs = p.split(path.sep) if (dirs[1] === 'core') { - buildCore(); + buildCore() } else if (dirs[2]) { - const name = path.basename(dirs[2], '.js'); + const name = path.basename(dirs[2], '.js') const input = `src/plugins/${name}${ /\.js/.test(dirs[2]) ? '' : '/index' - }.js`; + }.js` build({ input, - output: 'plugins/' + name + '.js', - }); + output: 'plugins/' + name + '.js' + }) } }) .on('ready', () => { - console.log('[start]'); - buildCore(); - buildAllPlugin(); - }); + console.log('[start]') + buildCore() + buildAllPlugin() + }) } else { - await Promise.all([buildCore(), buildAllPlugin()]); + await Promise.all([ + buildCore(), + buildAllPlugin() + ]) } } -main().catch(e => { - console.error(e); - process.exit(1); -}); +main().catch((e) => { + console.error(e) + process.exit(1) +}) + From e73d3e412b6726bae8fc7da549941f69663b4be5 Mon Sep 17 00:00:00 2001 From: John Hildenbiddle Date: Tue, 2 Aug 2022 13:47:06 -0500 Subject: [PATCH 16/16] Update to rollup@2 + terser --- build/build.js | 164 +++++++++++---------- package-lock.json | 359 +++++++++++++++++++++++++++++++++++----------- package.json | 4 +- 3 files changed, 362 insertions(+), 165 deletions(-) diff --git a/build/build.js b/build/build.js index 91155512a..483047765 100644 --- a/build/build.js +++ b/build/build.js @@ -1,13 +1,13 @@ -const rollup = require('rollup') -const buble = require('rollup-plugin-buble') -const commonjs = require('rollup-plugin-commonjs') -const nodeResolve = require('rollup-plugin-node-resolve') -const { uglify } = require('rollup-plugin-uglify') -const replace = require('rollup-plugin-replace') -const isProd = process.env.NODE_ENV === 'production' -const version = process.env.VERSION || require('../package.json').version -const chokidar = require('chokidar') -const path = require('path') +const rollup = require('rollup'); +const buble = require('rollup-plugin-buble'); +const commonjs = require('rollup-plugin-commonjs'); +const nodeResolve = require('rollup-plugin-node-resolve'); +const { terser } = require('rollup-plugin-terser'); +const replace = require('rollup-plugin-replace'); +const isProd = process.env.NODE_ENV === 'production'; +const version = process.env.VERSION || require('../package.json').version; +const chokidar = require('chokidar'); +const path = require('path'); /** * @param {{ @@ -24,90 +24,100 @@ async function build(opts) { plugins: (opts.plugins || []).concat([ buble({ transforms: { - dangerousForOf: true - }}), + dangerousForOf: true, + }, + }), commonjs(), nodeResolve(), replace({ __VERSION__: version, - 'process.env.SSR': false - }) + 'process.env.SSR': false, + }), ]), onwarn: function (message) { if (message.code === 'UNRESOLVED_IMPORT') { throw new Error( `Could not resolve module ` + - message.source + - `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` + - `Module ${message.source} is imported in ${message.importer}` - ) + message.source + + `. Try running 'npm install' or using rollup's 'external' option if this is an external dependency. ` + + `Module ${message.source} is imported in ${message.importer}` + ); } - } + }, }) .then(function (bundle) { - var dest = 'lib/' + (opts.output || opts.input) + var dest = 'lib/' + (opts.output || opts.input); - console.log(dest) + console.log(dest); return bundle.write({ format: 'iife', - output: opts.globalName ? {name: opts.globalName} : {}, + output: { + name: opts.globalName || null, + file: dest, + }, file: dest, - strict: false - }) - }) + strict: false, + }); + }); } async function buildCore() { - const promises = [] + const promises = []; - promises.push(build({ - input: 'src/core/index.js', - output: 'docsify.js', - })) + promises.push( + build({ + input: 'src/core/index.js', + output: 'docsify.js', + }) + ); if (isProd) { - promises.push(build({ - input: 'src/core/index.js', - output: 'docsify.min.js', - plugins: [uglify()] - })) + promises.push( + build({ + input: 'src/core/index.js', + output: 'docsify.min.js', + plugins: [terser()], + }) + ); } - await Promise.all(promises) + await Promise.all(promises); } async function buildAllPlugin() { var plugins = [ - {name: 'search', input: 'search/index.js'}, - {name: 'ga', input: 'ga.js'}, - {name: 'gtag', input: 'gtag.js'}, - {name: 'matomo', input: 'matomo.js'}, - {name: 'emoji', input: 'emoji.js'}, - {name: 'external-script', input: 'external-script.js'}, - {name: 'front-matter', input: 'front-matter/index.js'}, - {name: 'zoom-image', input: 'zoom-image.js'}, - {name: 'disqus', input: 'disqus.js'}, - {name: 'gitalk', input: 'gitalk.js'} - ] + { name: 'search', input: 'search/index.js' }, + { name: 'ga', input: 'ga.js' }, + { name: 'gtag', input: 'gtag.js' }, + { name: 'matomo', input: 'matomo.js' }, + { name: 'emoji', input: 'emoji.js' }, + { name: 'external-script', input: 'external-script.js' }, + { name: 'front-matter', input: 'front-matter/index.js' }, + { name: 'zoom-image', input: 'zoom-image.js' }, + { name: 'disqus', input: 'disqus.js' }, + { name: 'gitalk', input: 'gitalk.js' }, + ]; const promises = plugins.map(item => { return build({ input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.js' - }) - }) + output: 'plugins/' + item.name + '.js', + }); + }); if (isProd) { plugins.forEach(item => { - promises.push(build({ - input: 'src/plugins/' + item.input, - output: 'plugins/' + item.name + '.min.js', - plugins: [uglify()] - })) - }) + promises.push( + build({ + input: 'src/plugins/' + item.input, + output: 'plugins/' + item.name + '.min.js', + plugins: [terser()], + }) + ); + }); } - await Promise.all(promises) + await Promise.all(promises); } async function main() { @@ -117,41 +127,37 @@ async function main() { atomic: true, awaitWriteFinish: { stabilityThreshold: 1000, - pollInterval: 100 - } + pollInterval: 100, + }, }) .on('change', p => { - console.log('[watch] ', p) - const dirs = p.split(path.sep) + console.log('[watch] ', p); + const dirs = p.split(path.sep); if (dirs[1] === 'core') { - buildCore() + buildCore(); } else if (dirs[2]) { - const name = path.basename(dirs[2], '.js') + const name = path.basename(dirs[2], '.js'); const input = `src/plugins/${name}${ /\.js/.test(dirs[2]) ? '' : '/index' - }.js` + }.js`; build({ input, - output: 'plugins/' + name + '.js' - }) + output: 'plugins/' + name + '.js', + }); } }) .on('ready', () => { - console.log('[start]') - buildCore() - buildAllPlugin() - }) + console.log('[start]'); + buildCore(); + buildAllPlugin(); + }); } else { - await Promise.all([ - buildCore(), - buildAllPlugin() - ]) + await Promise.all([buildCore(), buildAllPlugin()]); } } -main().catch((e) => { - console.error(e) - process.exit(1) -}) - +main().catch(e => { + console.error(e); + process.exit(1); +}); diff --git a/package-lock.json b/package-lock.json index 2212e07e0..675133849 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48,13 +48,13 @@ "npm-run-all": "^4.1.5", "prettier": "^2.5.1", "rimraf": "^3.0.0", - "rollup": "^1.23.1", + "rollup": "^2.77.2", "rollup-plugin-async": "^1.2.0", "rollup-plugin-buble": "^0.19.8", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-replace": "^2.2.0", - "rollup-plugin-uglify": "^6.0.4", + "rollup-plugin-terser": "^7.0.2", "serve-handler": "^6.1.2", "stylus": "^0.54.5", "vue2": "npm:vue@^2.6.12", @@ -2777,6 +2777,64 @@ "node": ">=8" } }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "dependencies": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.14", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz", + "integrity": "sha512-bJWEfQ9lPTvm3SneWwRFVLzrh6nhjwqw7TUFFBEMzwvg7t7PCDenf2lDwqo4NQXzdpgBXyFgDWnQA+2vkruksQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "node_modules/@lerna/add": { "version": "3.21.0", "resolved": "https://registry.npmjs.org/@lerna/add/-/add-3.21.0.tgz", @@ -20504,6 +20562,15 @@ "node": ">=8" } }, + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "dependencies": { + "safe-buffer": "^5.1.0" + } + }, "node_modules/range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -21232,23 +21299,24 @@ } }, "node_modules/rollup": { - "version": "1.32.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz", - "integrity": "sha512-/2HA0Ec70TvQnXdzynFffkjA6XN+1e2pEv/uKS5Ulca40g2L7KuOE3riasHoNVHOsFD5KKZgDsMk1CP3Tw9s+A==", + "version": "2.77.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.77.2.tgz", + "integrity": "sha512-m/4YzYgLcpMQbxX3NmAqDvwLATZzxt8bIegO78FZLl+lAgKJBd1DRAOeEiZcKOIOPjxE6ewHWHNgGEalFXuz1g==", "dev": true, - "dependencies": { - "@types/estree": "*", - "@types/node": "*", - "acorn": "^7.1.0" - }, "bin": { "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=10.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" } }, "node_modules/rollup-plugin-async": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/rollup-plugin-async/-/rollup-plugin-async-1.2.0.tgz", - "integrity": "sha1-+V/dKfi28jMrWomp1k7oCHsSskk=", + "integrity": "sha512-5/LCGFDejG5OwfiNp377VqMjLQz87LBs4cXUfNiHHxrwd9RixiGgFDfv/4+KD9eKENr/bmUVwFRgMsL2mJW7Ag==", "dev": true, "dependencies": { "async-to-gen": "^1.2.0", @@ -21365,44 +21433,54 @@ "estree-walker": "^0.6.1" } }, - "node_modules/rollup-plugin-uglify": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.4.tgz", - "integrity": "sha512-ddgqkH02klveu34TF0JqygPwZnsbhHVI6t8+hGTcYHngPkQb5MIHI0XiztXIN/d6V9j+efwHAqEL7LspSxQXGw==", + "node_modules/rollup-plugin-terser": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz", + "integrity": "sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.0.0", - "jest-worker": "^24.0.0", - "serialize-javascript": "^2.1.2", - "uglify-js": "^3.4.9" + "@babel/code-frame": "^7.10.4", + "jest-worker": "^26.2.1", + "serialize-javascript": "^4.0.0", + "terser": "^5.0.0" }, "peerDependencies": { - "rollup": ">=0.66.0 <2" + "rollup": "^2.0.0" } }, - "node_modules/rollup-plugin-uglify/node_modules/jest-worker": { - "version": "24.9.0", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-24.9.0.tgz", - "integrity": "sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw==", + "node_modules/rollup-plugin-terser/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/rollup-plugin-terser/node_modules/jest-worker": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz", + "integrity": "sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==", "dev": true, "dependencies": { + "@types/node": "*", "merge-stream": "^2.0.0", - "supports-color": "^6.1.0" + "supports-color": "^7.0.0" }, "engines": { - "node": ">= 6" + "node": ">= 10.13.0" } }, - "node_modules/rollup-plugin-uglify/node_modules/supports-color": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", - "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "node_modules/rollup-plugin-terser/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "dependencies": { - "has-flag": "^3.0.0" + "has-flag": "^4.0.0" }, "engines": { - "node": ">=6" + "node": ">=8" } }, "node_modules/rollup-pluginutils": { @@ -21421,18 +21499,6 @@ "integrity": "sha1-va/oCVOD2EFNXcLs9MkXO225QS4=", "dev": true }, - "node_modules/rollup/node_modules/acorn": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", - "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", - "dev": true, - "bin": { - "acorn": "bin/acorn" - }, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/run-async": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.1.tgz", @@ -21658,10 +21724,13 @@ } }, "node_modules/serialize-javascript": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-2.1.2.tgz", - "integrity": "sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==", - "dev": true + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz", + "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==", + "dev": true, + "dependencies": { + "randombytes": "^2.1.0" + } }, "node_modules/serve-handler": { "version": "6.1.3", @@ -23341,6 +23410,42 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/terser": { + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", + "dev": true, + "dependencies": { + "@jridgewell/source-map": "^0.3.2", + "acorn": "^8.5.0", + "commander": "^2.20.0", + "source-map-support": "~0.5.20" + }, + "bin": { + "terser": "bin/terser" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/terser/node_modules/acorn": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", + "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/terser/node_modules/commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -23797,6 +23902,7 @@ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.14.5.tgz", "integrity": "sha512-qZukoSxOG0urUTvjc2ERMTcAy+BiFh3weWAkeurLwjrCba73poHmG3E36XEjd/JGukMzwTL7uCxZiAexj8ppvQ==", "dev": true, + "optional": true, "bin": { "uglifyjs": "bin/uglifyjs" }, @@ -26794,6 +26900,55 @@ } } }, + "@jridgewell/gen-mapping": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", + "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", + "dev": true, + "requires": { + "@jridgewell/set-array": "^1.0.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/resolve-uri": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", + "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", + "dev": true + }, + "@jridgewell/set-array": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.2.tgz", + "integrity": "sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==", + "dev": true + }, + "@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dev": true, + "requires": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, + "@jridgewell/sourcemap-codec": { + "version": "1.4.14", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", + "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", + "dev": true + }, + "@jridgewell/trace-mapping": { + "version": "0.3.14", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.14.tgz", + "integrity": "sha512-bJWEfQ9lPTvm3SneWwRFVLzrh6nhjwqw7TUFFBEMzwvg7t7PCDenf2lDwqo4NQXzdpgBXyFgDWnQA+2vkruksQ==", + "dev": true, + "requires": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, "@lerna/add": { "version": "3.21.0", "resolved": "https://registry.npmjs.org/@lerna/add/-/add-3.21.0.tgz", @@ -41052,6 +41207,15 @@ "integrity": "sha512-ARhCpm70fzdcvNQfPoy49IaanKkTlRWF2JMzqhcJbhSFRZv7nPTvZJdcY7301IPmvW+/p0RgIWnQDLJxifsQ7g==", "dev": true }, + "randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "dev": true, + "requires": { + "safe-buffer": "^5.1.0" + } + }, "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", @@ -41640,28 +41804,18 @@ } }, "rollup": { - "version": "1.32.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.32.1.tgz", - "integrity": "sha512-/2HA0Ec70TvQnXdzynFffkjA6XN+1e2pEv/uKS5Ulca40g2L7KuOE3riasHoNVHOsFD5KKZgDsMk1CP3Tw9s+A==", + "version": "2.77.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.77.2.tgz", + "integrity": "sha512-m/4YzYgLcpMQbxX3NmAqDvwLATZzxt8bIegO78FZLl+lAgKJBd1DRAOeEiZcKOIOPjxE6ewHWHNgGEalFXuz1g==", "dev": true, "requires": { - "@types/estree": "*", - "@types/node": "*", - "acorn": "^7.1.0" - }, - "dependencies": { - "acorn": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", - "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", - "dev": true - } + "fsevents": "~2.3.2" } }, "rollup-plugin-async": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/rollup-plugin-async/-/rollup-plugin-async-1.2.0.tgz", - "integrity": "sha1-+V/dKfi28jMrWomp1k7oCHsSskk=", + "integrity": "sha512-5/LCGFDejG5OwfiNp377VqMjLQz87LBs4cXUfNiHHxrwd9RixiGgFDfv/4+KD9eKENr/bmUVwFRgMsL2mJW7Ag==", "dev": true, "requires": { "async-to-gen": "^1.2.0", @@ -41776,35 +41930,42 @@ } } }, - "rollup-plugin-uglify": { - "version": "6.0.4", - "resolved": "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.4.tgz", - "integrity": "sha512-ddgqkH02klveu34TF0JqygPwZnsbhHVI6t8+hGTcYHngPkQb5MIHI0XiztXIN/d6V9j+efwHAqEL7LspSxQXGw==", + "rollup-plugin-terser": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz", + "integrity": "sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==", "dev": true, "requires": { - "@babel/code-frame": "^7.0.0", - "jest-worker": "^24.0.0", - "serialize-javascript": "^2.1.2", - "uglify-js": "^3.4.9" + "@babel/code-frame": "^7.10.4", + "jest-worker": "^26.2.1", + "serialize-javascript": "^4.0.0", + "terser": "^5.0.0" }, "dependencies": { + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, "jest-worker": { - "version": "24.9.0", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-24.9.0.tgz", - "integrity": "sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw==", + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz", + "integrity": "sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==", "dev": true, "requires": { + "@types/node": "*", "merge-stream": "^2.0.0", - "supports-color": "^6.1.0" + "supports-color": "^7.0.0" } }, "supports-color": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", - "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "dev": true, "requires": { - "has-flag": "^3.0.0" + "has-flag": "^4.0.0" } } } @@ -42009,10 +42170,13 @@ } }, "serialize-javascript": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-2.1.2.tgz", - "integrity": "sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==", - "dev": true + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz", + "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==", + "dev": true, + "requires": { + "randombytes": "^2.1.0" + } }, "serve-handler": { "version": "6.1.3", @@ -43369,6 +43533,32 @@ } } }, + "terser": { + "version": "5.14.2", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.2.tgz", + "integrity": "sha512-oL0rGeM/WFQCUd0y2QrWxYnq7tfSuKBiqTjRPWrRgB46WD/kiwHwF8T23z78H6Q6kGCuuHcPB+KULHRdxvVGQA==", + "dev": true, + "requires": { + "@jridgewell/source-map": "^0.3.2", + "acorn": "^8.5.0", + "commander": "^2.20.0", + "source-map-support": "~0.5.20" + }, + "dependencies": { + "acorn": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz", + "integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==", + "dev": true + }, + "commander": { + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "dev": true + } + } + }, "test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -43727,7 +43917,8 @@ "version": "3.14.5", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.14.5.tgz", "integrity": "sha512-qZukoSxOG0urUTvjc2ERMTcAy+BiFh3weWAkeurLwjrCba73poHmG3E36XEjd/JGukMzwTL7uCxZiAexj8ppvQ==", - "dev": true + "dev": true, + "optional": true }, "uid-number": { "version": "0.0.6", diff --git a/package.json b/package.json index bca7700db..5ffac4444 100644 --- a/package.json +++ b/package.json @@ -103,13 +103,13 @@ "npm-run-all": "^4.1.5", "prettier": "^2.5.1", "rimraf": "^3.0.0", - "rollup": "^1.23.1", + "rollup": "^2.77.2", "rollup-plugin-async": "^1.2.0", "rollup-plugin-buble": "^0.19.8", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-plugin-replace": "^2.2.0", - "rollup-plugin-uglify": "^6.0.4", + "rollup-plugin-terser": "^7.0.2", "serve-handler": "^6.1.2", "stylus": "^0.54.5", "vue2": "npm:vue@^2.6.12",