-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a2fb2c
commit 0081cdc
Showing
3 changed files
with
110 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters