diff --git a/.github/workflows/size.yml b/.github/workflows/size.yml index 3d3900c8d..081d16cd6 100644 --- a/.github/workflows/size.yml +++ b/.github/workflows/size.yml @@ -15,4 +15,5 @@ jobs: with: node-version: ${{ matrix.node-version }} - run: yarn install + - run: yarn build - run: yarn size \ No newline at end of file diff --git a/config/rollup.main-thread.js b/config/rollup.main-thread.js index ae2dfdcf1..2b3199818 100644 --- a/config/rollup.main-thread.js +++ b/config/rollup.main-thread.js @@ -14,8 +14,6 @@ * limitations under the License. */ -import compiler from '@ampproject/rollup-plugin-closure-compiler'; -import { terser } from 'rollup-plugin-terser'; import replace from '@rollup/plugin-replace'; import { babelPlugin, removeDebugCommandExecutors, removeWorkerWhitespace } from './rollup.plugins.js'; @@ -34,11 +32,8 @@ const ESModules = [ WORKER_DOM_DEBUG: false, }), babelPlugin({ - transpileToES5: false, allowConsole: false, }), - compiler(), - terser(), ], }, { @@ -54,7 +49,6 @@ const ESModules = [ WORKER_DOM_DEBUG: true, }), babelPlugin({ - transpileToES5: false, allowConsole: true, }), ], @@ -73,11 +67,8 @@ const ESModules = [ WORKER_DOM_DEBUG: false, }), babelPlugin({ - transpileToES5: false, allowConsole: false, }), - compiler(), - terser(), ], }, { @@ -93,57 +84,10 @@ const ESModules = [ WORKER_DOM_DEBUG: true, }), babelPlugin({ - transpileToES5: false, allowConsole: true, }), ], }, ]; -const IIFEModules = [ - { - input: 'output/main-thread/index.js', - output: { - file: 'dist/main.js', - format: 'iife', - name: 'MainThread', - sourcemap: true, - }, - plugins: [ - removeWorkerWhitespace(), - removeDebugCommandExecutors(), - replace({ - WORKER_DOM_DEBUG: false, - }), - babelPlugin({ - transpileToES5: true, - allowConsole: false, - }), - compiler(), - terser(), - ], - }, - { - input: 'output/main-thread/index.js', - output: { - file: 'dist/debug/main.js', - format: 'iife', - name: 'MainThread', - sourcemap: true, - }, - plugins: [ - removeWorkerWhitespace(), - replace({ - WORKER_DOM_DEBUG: true, - }), - babelPlugin({ - transpileToES5: true, - allowConsole: true, - }), - compiler(), - terser(), - ], - }, -]; - -export default [...ESModules, ...IIFEModules]; +export default [...ESModules]; diff --git a/config/rollup.plugins.js b/config/rollup.plugins.js index 45a698cfe..cc4818801 100644 --- a/config/rollup.plugins.js +++ b/config/rollup.plugins.js @@ -14,7 +14,7 @@ * limitations under the License. */ -import babel from 'rollup-plugin-babel'; +import babel from '@rollup/plugin-babel'; import MagicString from 'magic-string'; import fs from 'fs'; import * as path from 'path'; @@ -27,42 +27,13 @@ const walk = require('acorn-walk'); * - allowConsole Should we allow `console` methods in the output? * - allowPostMessage Should we allow postMessage to/from the Worker? */ -export function babelPlugin({ transpileToES5, allowConsole = false, allowPostMessage = true }) { - const targets = transpileToES5 ? { browsers: ['last 2 versions', 'ie >= 11', 'safari >= 7'] } : { esmodules: true }; +export function babelPlugin({ allowConsole = false }) { const exclude = allowConsole ? ['error', 'warn', 'trace', 'info', 'log', 'time', 'timeEnd'] : []; return babel({ exclude: 'node_modules/**', - presets: [ - [ - '@babel/env', - { - targets, - loose: !transpileToES5, - modules: false, - bugfixes: true, - }, - ], - ], - plugins: [ - ['@babel/plugin-proposal-object-rest-spread'], - ['@babel/proposal-class-properties'], - [ - 'babel-plugin-minify-replace', - { - replacements: [ - { - identifierName: '__ALLOW_POST_MESSAGE__', - replacement: { - type: 'booleanLiteral', - value: allowPostMessage, - }, - }, - ], - }, - ], - ['babel-plugin-transform-remove-console', { exclude }], - ], + babelHelpers: 'bundled', + plugins: [['babel-plugin-transform-remove-console', { exclude }]], }); } diff --git a/config/rollup.worker-thread.js b/config/rollup.worker-thread.js index 4191d5325..c407671eb 100644 --- a/config/rollup.worker-thread.js +++ b/config/rollup.worker-thread.js @@ -14,19 +14,9 @@ * limitations under the License. */ -import compiler from '@ampproject/rollup-plugin-closure-compiler'; -import { terser } from 'rollup-plugin-terser'; import replace from '@rollup/plugin-replace'; import { babelPlugin } from './rollup.plugins.js'; -// Compile plugins should always be added at the end of the plugin list. -const compilePlugins = [ - compiler({ - env: 'CUSTOM', - }), - terser(), -]; - // Workers do not natively support ES Modules containing `import` or `export` statments. // So, here we continue to use the '.mjs' extension to indicate newer ECMASCRIPT support // but ensure the code can be run within a worker by putting it inside a named iife. @@ -44,10 +34,8 @@ const ESModules = [ WORKER_DOM_DEBUG: false, }), babelPlugin({ - transpileToES5: false, allowConsole: false, }), - ...compilePlugins, ], }, { @@ -63,7 +51,6 @@ const ESModules = [ WORKER_DOM_DEBUG: true, }), babelPlugin({ - transpileToES5: false, allowConsole: true, }), ], @@ -81,10 +68,8 @@ const ESModules = [ WORKER_DOM_DEBUG: false, }), babelPlugin({ - transpileToES5: false, allowConsole: false, }), - ...compilePlugins, ], }, { @@ -97,44 +82,6 @@ const ESModules = [ }, plugins: [ babelPlugin({ - transpileToES5: false, - allowConsole: true, - }), - ], - }, - { - input: 'output/worker-thread/index.amp.js', - output: { - file: 'dist/amp-production/worker/worker.js', - format: 'iife', - name: 'WorkerThread', - sourcemap: true, - }, - plugins: [ - replace({ - WORKER_DOM_DEBUG: false, - }), - babelPlugin({ - transpileToES5: true, - allowConsole: false, - }), - ...compilePlugins, - ], - }, - { - input: 'output/worker-thread/index.amp.js', - output: { - file: 'dist/amp-debug/worker/worker.js', - format: 'iife', - name: 'WorkerThread', - sourcemap: true, - }, - plugins: [ - replace({ - WORKER_DOM_DEBUG: true, - }), - babelPlugin({ - transpileToES5: true, allowConsole: true, }), ], @@ -152,10 +99,8 @@ const ESModules = [ WORKER_DOM_DEBUG: false, }), babelPlugin({ - transpileToES5: false, allowConsole: true, }), - ...compilePlugins, ], }, { @@ -171,88 +116,10 @@ const ESModules = [ WORKER_DOM_DEBUG: true, }), babelPlugin({ - transpileToES5: false, - allowConsole: true, - }), - ], - }, - { - input: 'output/worker-thread/index.nodom.amp.js', - output: { - file: 'dist/amp-production/worker/worker.nodom.js', - format: 'iife', - name: 'WorkerThread', - sourcemap: true, - }, - plugins: [ - replace({ - WORKER_DOM_DEBUG: false, - }), - babelPlugin({ - transpileToES5: true, - allowConsole: false, - }), - ...compilePlugins, - ], - }, - { - input: 'output/worker-thread/index.nodom.amp.js', - output: { - file: 'dist/amp-debug/worker/worker.nodom.js', - format: 'iife', - name: 'WorkerThread', - sourcemap: true, - }, - plugins: [ - replace({ - WORKER_DOM_DEBUG: true, - }), - babelPlugin({ - transpileToES5: true, - allowConsole: true, - }), - ], - }, -]; - -const IIFEModules = [ - { - input: 'output/worker-thread/index.js', - output: { - file: 'dist/worker/worker.js', - format: 'iife', - name: 'WorkerThread', - sourcemap: true, - }, - plugins: [ - replace({ - WORKER_DOM_DEBUG: false, - }), - babelPlugin({ - transpileToES5: true, - allowConsole: false, - }), - ...compilePlugins, - ], - }, - { - input: 'output/worker-thread/index.js', - output: { - file: 'dist/debug/worker/worker.js', - format: 'iife', - name: 'WorkerThread', - sourcemap: true, - }, - plugins: [ - replace({ - WORKER_DOM_DEBUG: true, - }), - babelPlugin({ - transpileToES5: true, allowConsole: true, }), ], }, ]; -export default [...ESModules, ...IIFEModules]; +export default [...ESModules]; diff --git a/demo/call-function/index.html b/demo/call-function/index.html index 5c7a473dc..d8d425522 100644 --- a/demo/call-function/index.html +++ b/demo/call-function/index.html @@ -4,7 +4,7 @@