Statically apply Polymer's CSS Mixin shim and ShadyDOM scoping
- (Optionally) Bundle your project
- Checkout this tool
npm install
node bin/polymer-css-build path/to/vulcanized-file.html
- Set
--polymer-version
flag to1
or2
- If multiple files are passed, they are expected to be all of the dependencies used during the lifecycle of the application.
- Output file names should be specified in the same order as input files
We define "targeted builds" to mean that when using the the defaults of Polymer 2, and {dom: shadow}
option for Polymer 1,
no work will be done by ShadyCSS at runtime.
By default, polymer-css-build
will produce built styles that are targeted for ShadowDOM.
This is done because ShadowDOM is the default for Polymer v2, and these styles can still be used in ShadyDOM mode with some runtime work,
and the built styles are portable to both Polymer ShadyDOM and ShadowDOM scoping modes.
Polymer 1.x by default uses ShadyDOM, a lightweight shim of the ShadowDOM spec.
If your app only uses ShadyDOM, then some runtime work is still done to convert CSS selectors under the default settings.
To produce a targeted build for ShadyDOM, pass the --build-for-shady
flag on the command line, or {'build-for-shady': true}
to the library.
However, these styles will only work with ShadyDOM enabled, and the modifications for ShadyDOM remove some CSS selector information necessary for ShadowDOM.
polymer-css-build
uses @webcomponents/shadycss
for transforming stylesheets since v0.3.0, which is what Polymer 2 and 3 use for ShadyDOM support and @apply
mixins.
Polymer 1.x uses a few style transforms that are either deprecated, or behave differently from what is implemented in ShadyCSS.
Setting --polymer-version=1
on the command line, or {'polymer-version': '1'}
via the library will enable these transforms for use with projects using Polymer 1.x
By default, the version of Polymer is assumed to be "2".
Polymer 2 and 3 support inlining templates either with the legacy Polymer()
syntax, or extending Polymer.Element
.
-
In both cases,
polymer-css-build
only supports inlined templates if they are made using thehtml
tagged template function, and are not referenced via a variable, as illustrated by the samples below. -
Also, interpolations such as
Polymer.html`<style>${variable}</style><div></div>`
are not supported.
Polymer({
is: 'legacy-inline-element',
_template: Polymer.html`
<style>...</style>
<div id="hello"></div>
`;
})
class InlineElement extends Polymer.Element {
static get is() {
return 'inline-element'
}
static get template() {
return Polymer.html`
<style>...</style>
<div id="hello"></div>
`
}
}