Skip to content

Commit

Permalink
feat(build): configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
MM25Zamanian committed Dec 3, 2022
1 parent 0a2fb2c commit 0081cdc
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 37 deletions.
12 changes: 11 additions & 1 deletion pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,16 @@
"@alwatr/router": "~0.24.1",
"@alwatr/signal": "~0.24.1",
"@ionic/core": "~6.3.9",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.0.1",
"@web/rollup-plugin-copy": "^0.3.0",
"@web/rollup-plugin-html": "^1.11.0",
"@web/rollup-plugin-polyfills-loader": "^1.3.1",
"@webcomponents/webcomponentsjs": "~2.7.0",
"lit": "~2.4.1"
"lit": "~2.4.1",
"rollup-plugin-minify-html-literals": "^1.2.6",
"rollup-plugin-summary": "^2.0.0",
"rollup-plugin-terser": "^7.0.2"
},
"devDependencies": {
"@babel/preset-env": "~7.20.2",
Expand All @@ -48,6 +56,8 @@
"@rollup/plugin-node-resolve": "~15.0.1",
"@web/dev-server": "~0.1.35",
"@web/dev-server-esbuild": "^0.3.3",
"@web/rollup-plugin-copy": "^0.3.0",
"@web/rollup-plugin-html": "^1.11.0",
"deepmerge": "~4.2.2",
"eslint-plugin-lit": "^1.6.1",
"lit-analyzer": "^1.2.1",
Expand Down
114 changes: 85 additions & 29 deletions pwa/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,109 @@
// Import rollup plugins
import {rollupPluginHTML} from '@web/rollup-plugin-html';
import {polyfillsLoader} from '@web/rollup-plugin-polyfills-loader';
import {copy} from '@web/rollup-plugin-copy';
import resolve from '@rollup/plugin-node-resolve';
// import {getBabelOutputPlugin} from '@rollup/plugin-babel';
import {getBabelOutputPlugin} from '@rollup/plugin-babel';
import {terser} from 'rollup-plugin-terser';
import minifyHTML from 'rollup-plugin-minify-html-literals';
import summary from 'rollup-plugin-summary';
import {terser} from 'rollup-plugin-terser';

function onwarn(warning) {
if (warning.code !== 'THIS_IS_UNDEFINED') {
console.error(`(!) ${warning.message}`);
}
}
// Configure an instance of @web/rollup-plugin-html
const htmlPlugin = rollupPluginHTML({
rootDir: './',
flattenOutput: false,
});

export default {
input: 'src/alwatr-pwa.js',
treeshake: true,
// Entry point for application build; can specify a glob to build multiple
// HTML files for non-SPA app
input: 'index.html',
plugins: [
htmlPlugin,
// Resolve bare module specifiers to relative paths
resolve(),
// Minify HTML template literals
minifyHTML.default(),
// Minify JS
terser({
compress: true,
ecma: 2018,
module: true,
warnings: true,
format: {
comments: false,
}),
// Inject polyfills into HTML (core-js, regnerator-runtime, webcoponents,
// lit/polyfill-support) and dynamically loads modern vs. legacy builds
polyfillsLoader({
modernOutput: {
name: 'modern',
},
mangle: {
properties: {
regex: /^__/,
},
// Feature detection for loading legacy bundles
legacyOutput: {
name: 'legacy',
test: '!!Array.prototype.flat',
type: 'systemjs',
},
// List of polyfills to inject (each has individual feature detection)
polyfills: {
hash: true,
coreJs: true,
regeneratorRuntime: true,
fetch: true,
webcomponents: true,
// Custom configuration for loading Lit's polyfill-support module,
// required for interfacing with the webcomponents polyfills
custom: [
{
name: 'lit-polyfill-support',
path: 'node_modules/lit/polyfill-support.js',
test: "!('attachShadow' in Element.prototype)",
module: false,
},
],
},
}),
// Print bundle summary
summary(),
// Optional: copy any static assets to build directory
copy({
patterns: ['images/**/*'],
}),
],
// Specifies two JS output configurations, modern and legacy, which the HTML plugin will
// automatically choose between; the legacy build is compiled to ES5
// and SystemJS modules
output: [
{
// Modern JS bundles (no JS compilation, ES module output)
format: 'esm',
chunkFileNames: '[name]-[hash].js',
entryFileNames: '[name]-[hash].js',
dir: 'build',
plugins: [htmlPlugin.api.addOutput('modern')],
},
{
// Legacy JS bundles (ES5 compilation and SystemJS module output)
format: 'esm',
entryFileNames: '[name].esm.js',
chunkFileNames: 'legacy-[name]-[hash].js',
entryFileNames: 'legacy-[name]-[hash].js',
dir: 'build',
plugins: [
htmlPlugin.api.addOutput('legacy'),
// Uses babel to compile JS to ES5 and modules to SystemJS
getBabelOutputPlugin({
compact: true,
presets: [
[
'@babel/preset-env',
{
targets: {
ie: '11',
},
modules: 'systemjs',
},
],
],
}),
],
},
// {
// dir: 'build',
// format: 'esm',
// entryFileNames: '[name].es5.js',
// plugins: [
// getBabelOutputPlugin({
// compact: true,
// presets: [['@babel/preset-env', {modules: 'systemjs'}]]
// }),
// ]
// },
],
preserveEntrySignatures: false,
};
21 changes: 14 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@
"@babel/helper-module-imports" "^7.10.4"
"@rollup/pluginutils" "^3.1.0"

"@rollup/plugin-babel@~6.0.3":
"@rollup/plugin-babel@^6.0.3":
version "6.0.3"
resolved "https://registry.yarnpkg.com/@rollup/plugin-babel/-/plugin-babel-6.0.3.tgz#07ccde15de278c581673034ad6accdb4a153dfeb"
integrity sha512-fKImZKppa1A/gX73eg4JGo+8kQr/q1HBQaCGKECZ0v4YBBv3lFqi14+7xyApECzvkLTHCifx+7ntcrvtBIRcpg==
Expand Down Expand Up @@ -1294,7 +1294,7 @@
is-module "^1.0.0"
resolve "^1.19.0"

"@rollup/plugin-node-resolve@~15.0.1":
"@rollup/plugin-node-resolve@^15.0.1":
version "15.0.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.0.1.tgz#72be449b8e06f6367168d5b3cd5e2802e0248971"
integrity sha512-ReY88T7JhJjeRVbfCyNj+NXAG3IIsVMsX9b5/9jC98dRP8/yxlZdz7mHZbHk5zHr24wZZICS5AcXsFZAXYUQEg==
Expand Down Expand Up @@ -1764,7 +1764,14 @@
terser "^5.14.2"
whatwg-fetch "^3.5.0"

"@web/rollup-plugin-html@^1.7.0":
"@web/rollup-plugin-copy@^0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@web/rollup-plugin-copy/-/rollup-plugin-copy-0.3.0.tgz#fe999b2ea3dd71c8e663e6947fc2eb92a221e8e8"
integrity sha512-QNNtE7Svhk0/p21etaR0JQXYhlMgTAg/HmRXDMmQHMf3uOUWsWMGiJa96P49RRVJut1ECB5FDFeBUgFEmegysQ==
dependencies:
glob "^7.1.6"

"@web/rollup-plugin-html@^1.11.0", "@web/rollup-plugin-html@^1.7.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@web/rollup-plugin-html/-/rollup-plugin-html-1.11.0.tgz#46c2bcb3a3b9db55d53b897ffc7e7ef2f618a052"
integrity sha512-EqUcV5plGYTV/utdbX8g5t8Yq/z6VfFuQuPD39ckOQuRj7Rj6HD15FHwLHpFAWOR0+GrDnNzR74RvI4ipGm0qQ==
Expand All @@ -1783,7 +1790,7 @@
estree-walker "^2.0.2"
magic-string "^0.25.7"

"@web/rollup-plugin-polyfills-loader@^1.1.0":
"@web/rollup-plugin-polyfills-loader@^1.1.0", "@web/rollup-plugin-polyfills-loader@^1.3.1":
version "1.3.1"
resolved "https://registry.yarnpkg.com/@web/rollup-plugin-polyfills-loader/-/rollup-plugin-polyfills-loader-1.3.1.tgz#8cd22da8e7c661897285cae90e3b4bdf464dfdca"
integrity sha512-dV73QWsGMFkCGwgs2l6ADmDFtsEIduTJLSBL5wBHp5wZm1Sy4SQAEGTsDMRDX5cpAHRT9+sUnKLLREfBppuJbA==
Expand Down Expand Up @@ -5022,15 +5029,15 @@ rimraf@^3.0.2, rimraf@~3.0.2:
dependencies:
glob "^7.1.3"

rollup-plugin-minify-html-literals@~1.2.6:
rollup-plugin-minify-html-literals@^1.2.6:
version "1.2.6"
resolved "https://registry.yarnpkg.com/rollup-plugin-minify-html-literals/-/rollup-plugin-minify-html-literals-1.2.6.tgz#775d9502e786ac6a4fc23ac53e5cb1658627938b"
integrity sha512-JRq2fjlCTiw0zu+1Sy3ClHGCxA79dWGr4HLHWSQgd060StVW9fBVksuj8Xw/suPkNSGClJf/4xNQ1MF6JeXPaw==
dependencies:
minify-html-literals "^1.3.5"
rollup-pluginutils "^2.8.2"

rollup-plugin-summary@~2.0.0:
rollup-plugin-summary@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-summary/-/rollup-plugin-summary-2.0.0.tgz#ad228d3eb897140d3b7f71e0b23b71b2f2352df3"
integrity sha512-7Av6DQeCmVNpFmCdkkbMya1CneeGWhjSXXQ3B4yDO+BvN/Kbohqi3IEYXAvgHP3iIafSfMyOw+PBLFUlvf1ViA==
Expand All @@ -5041,7 +5048,7 @@ rollup-plugin-summary@~2.0.0:
gzip-size "^7.0.0"
terser "^5.15.1"

rollup-plugin-terser@^7.0.0, rollup-plugin-terser@^7.0.2, rollup-plugin-terser@~7.0.2:
rollup-plugin-terser@^7.0.0, rollup-plugin-terser@^7.0.2:
version "7.0.2"
resolved "https://registry.yarnpkg.com/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz#e8fbba4869981b2dc35ae7e8a502d5c6c04d324d"
integrity sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==
Expand Down

0 comments on commit 0081cdc

Please sign in to comment.