Skip to content

Commit

Permalink
#2329 Moved from polymer-based tree shaking to rollup-based.
Browse files Browse the repository at this point in the history
This allows greater capabilities for importing libraries (like antlr4). polymer-cli is quite old and limited in that regard. Rollup also has a potential to import raw string from css files, which would hopefully also simplify libraries maintenance.

Many regenerated files are more close to npm-versions. That is not bad, because stripping of unnecessary braces or some other simplification of code is still done using terser during vulcanisation.

Also, rollup seems to be more strict during tree shaking (tree shakes more). However, exactly the same count of files returned (besides antlr4). Some files lost some (actually used) functions, but they were returned in subsequent tree regeneration commits.

 * Antlr library file are now tree-shaken through lib/antlr-lib.js file, which generates polymer/lib/antlr-lib.js (install-polymer.sh). The generated file is used for TG components.
 * Added some missing imports to tree shaker: dom-bind, dom-module, dom-repeat. They were not a problem because of transitive usage, but better to be included.
 * Added missing ';'.
  • Loading branch information
jhou-pro committed Dec 21, 2024
1 parent 3bef782 commit 361777d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 46 deletions.
8 changes: 4 additions & 4 deletions platform-web-ui/src/main/resources/build-polymer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import '@polymer/polymer/polymer-element.js';
import '@polymer/polymer/lib/elements/dom-bind.js';
import '@polymer/polymer/lib/elements/dom-module.js';
import '@polymer/polymer/lib/elements/dom-repeat.js';
import '@polymer/polymer/polymer-legacy.js';
import '@polymer/app-layout/app-drawer-layout/app-drawer-layout.js';
import '@polymer/app-layout/app-drawer/app-drawer.js';
Expand Down Expand Up @@ -64,10 +66,8 @@ import '@polymer/paper-radio-button/paper-radio-button.js';
import '@polymer/paper-spinner/paper-spinner.js';
import '@polymer/paper-styles/color.js';
import '@polymer/paper-styles/default-theme.js';
import '@polymer/paper-styles/paper-styles.js';
import '@polymer/paper-styles/paper-styles-classes.js';
import '@polymer/paper-styles/shadow.js';
import '@polymer/paper-styles/element-styles/paper-material-styles.js';
import '@polymer/paper-toast/paper-toast.js';
import '@polymer/paper-toolbar/paper-toolbar.js';
import '@google-web-components/google-chart/google-chart.js'
import '@google-web-components/google-chart/google-chart.js';
15 changes: 0 additions & 15 deletions platform-web-ui/src/main/resources/build.html

This file was deleted.

15 changes: 10 additions & 5 deletions platform-web-ui/src/main/resources/install-polymer.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
rm -f package-lock.json
npm install
rm -f node_modules/stacky
polymer build
cp -r lib node_modules/
rollup --config
rm -r -f polymer
mv node_modules polymer
rm -r -f polymer/@google-web-components
rm -r -f polymer/@polymer
rm -r -f polymer/@webcomponents
rm -r -f polymer/web-animations-js
mv build/tg-custom-build/node_modules/@google-web-components polymer/
mv build/tg-custom-build/node_modules/@polymer polymer/
mv build/tg-custom-build/node_modules/@webcomponents polymer/
mv build/tg-custom-build/node_modules/web-animations-js polymer/
rm -r -f polymer/lib
rm -r -f polymer/antlr4
mv build/node_modules/@google-web-components polymer/
mv build/node_modules/@polymer polymer/
mv build/node_modules/@webcomponents polymer/
mv build/node_modules/web-animations-js polymer/
mv build/node_modules/lib polymer/
mv build/node_modules/antlr4 polymer/
rm -r -f build
find polymer -type f -name "package.json" -delete
2 changes: 1 addition & 1 deletion platform-web-ui/src/main/resources/lib/antlr-lib.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import antlr4 from '/resources/polymer/antlr4/dist/antlr4.web.mjs';
import antlr4 from 'antlr4';
export default antlr4;
21 changes: 0 additions & 21 deletions platform-web-ui/src/main/resources/polymer.json

This file was deleted.

45 changes: 45 additions & 0 deletions platform-web-ui/src/main/resources/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';

export default {
input: [
// Polymer, its elements and Google elements.
'build-polymer.js',

// Our other libraries.
'node_modules/lib/antlr-lib.js',

// Polymer import files, that we are using through function imports, are listed here.
// They can not be added to 'build-polymer.js' because we would need to somehow use those functions there for them to be not tree-shaken.
'node_modules/@polymer/polymer/lib/legacy/class.js', // 'mixinBehaviors' is required (and not used transitively)
'node_modules/@polymer/polymer/lib/mixins/gesture-event-listeners.js', // (used transitively)
'node_modules/@polymer/polymer/lib/utils/flush.js', // (used transitively)
'node_modules/@polymer/polymer/lib/utils/render-status.js', // 'beforeNextRender' is required (and not used transitively)
'node_modules/@polymer/polymer/lib/utils/async.js', // (used transitively)
'node_modules/@polymer/polymer/lib/utils/flattened-nodes-observer.js', // (used transitively)
'node_modules/@polymer/polymer/lib/utils/html-tag.js', // (used transitively)
'node_modules/@polymer/polymer/lib/legacy/polymer-fn.js', // (used transitively)
'node_modules/@polymer/polymer/polymer-element.js', // (used transitively)

// These two files just perform imports with side effects and that's why they are tree-shaken if placed in 'build-polymer.js'.
'node_modules/@polymer/paper-styles/paper-styles.js',
'node_modules/@polymer/paper-styles/paper-styles-classes.js',

// Separate testing dependency -- we also tree shake it because placed under '@polymer/' umbrella.
'node_modules/@polymer/test-fixture/test-fixture.js',

// Separate production files, that are used through <script src='/resources/polymer/ ... /*.js'></script>.
'node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js',
'node_modules/web-animations-js/web-animations-next-lite.min.js'
],
output: {
dir: 'build',
format: 'es',
preserveModules: true
},
plugins: [
nodeResolve({
extensions: ['.js', '.mjs'],
browser: true // required for resolving browser-related file in libs like antlr4 (see 'exports' section in 'package.json' in https://www.npmjs.com/package/antlr4?activeTab=code)
})
]
};

0 comments on commit 361777d

Please sign in to comment.