Giter Site home page Giter Site logo

saitho / amp-css Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 1.25 MB

Provides a binary to compile SCSS files and validate them for AMP (Accelerated Mobile Pages).

Home Page: https://saitho.github.io/amp-css/

TypeScript 94.41% JavaScript 1.49% HTML 3.44% CSS 0.07% SCSS 0.59%
amp amp-html accelerated-mobile-pages scss amp-css insert-css

amp-css's Introduction

AMP-CSS

Dependency Status Build Status npm version npm license Known Vulnerabilities semantic-release Quality Gate Status Commitizen friendly

AMP (Accelerated Mobile Pages) is a project by Google and the Digital News Initiative aiming to improve the speed of websites by utilizing a special JavaScript framework.

This comes with restrictions to the size and contents of CSS. This package provides a binary to compile SCSS files only if the resulting CSS is valid for AMP. Also it provides a way to insert CSS into a (static) HTML page.

Installing

NPM

npm install --save-dev @saithodev/amp-css

PNPM

pnpm install --save-dev @saithodev/amp-css

Yarn

yarn add --dev @saithodev/amp-css

Command overview

Compile SCSS to CSS

The following example will compile the file path/to/my/scss/style.scss into the CSS file path/to/my/css/style.css if there is no invalid CSS inside and the file size does not exceed AMP's size limit.

amp-css process path/to/my/scss/style.scss path/to/my/css/style.css

Alternatively you can also set an output directory. The following line does exactly the same as the line above:

amp-css process --output-dir path/to/my/css path/to/my/scss/style.scss

Inserting CSS into a HTML file

AMP requires websites to embed the stylings using inline CSS. There is a command that will look for the "Custom AMP CSS" area in a HTML file and overwrite its contents with the content of a given CSS file.

amp-css assign -s mycss.css index.html

Using in build scripts

We recommend defining scripts inside your projects package.json:

"scripts": {
    "build": "npm run-script build-css && npm run-script assign-css",
    "build-css": "amp-css process -s assets/scss/styles.scss assets/css/styles.css",
    "assign-css": "amp-css assign -s assets/css/styles.css index.html"
}

In the example above calling npm run-script build (or yarn build) will compile the CSS file and insert it into the index.html file.

Processing multiple files

There currently is no support for compiling multiple SCSS files or inserting multiple CSS files. I currently don't see a use case for that.

If your stylings consists of multiple stylings, @import them all in one SCSS file which you then compile.

amp-css's People

Contributors

saitho avatar semantic-release-bot avatar snyk-bot avatar

Watchers

 avatar  avatar

Forkers

fossabot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.