PostCSS plugin to optimize CSS for Google AMP. A web interface is available at PostCSS Amplify.
This plugin works by filtering out:
- Media queries for desktop breakpoints
- Non
-webkit-
vendor prefixes - Specific class block names or other prefixes (for use with BEM or other namespacing methodologies)
!important
flags-amp
classes ori-amp
tags
For example, inputting:
body {
font-size: 14px;
}
@media (min-width: 768px) {
body {
font-size: 16px;
}
}
.heading {
color: #000 !important;
}
.menu {
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-ms-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
.-amp-image {
width: 300px;
}
would result in:
body {
font-size: 14px;
}
.heading {
color: #000;
}
.menu {
-webkit-transition: all 0.5s ease;
transition: all 0.5s ease;
}
Check your project for existing PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you already use PostCSS, add the plugin to plugins list:
module.exports = {
plugins: [
+ require('postcss-amplify')(options),
require('autoprefixer')
]
}
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
options.maxBreakpoint (string) To allow for larger mobile styling, media queries below this breakpoint will be preserved.
options.excludedBlocks (string or array) List of class block names or prefixes to exclude. Do not include the .
at the beginning of the name.
If you run into any unintended side effects or other bugs, please submit an issue.