Style your Angular website faster with Stylify CSS

Style your Angular app quickly and easily with Stylify CSS. Split CSS for large pages or create one bundle for a whole app and get extremely small CSS.

Introduction

Stylify is a library that uses CSS-like selectors to generate optimized uti…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Vladimír Macháček

Style your Angular app quickly and easily with Stylify CSS. Split CSS for large pages or create one bundle for a whole app and get extremely small CSS.

Introduction

Stylify is a library that uses CSS-like selectors to generate optimized utility-first CSS based on what you write.

✨CSS-like selectors
💎No framework to study
💡Less time spent in docs
🧰Mangled & Extremely small CSS
🤘No purge needed
🚀Components, Variables, Custom selectors
📦It can generate multiple CSS bundles

Installation

First install the @stylify/bundler package using NPM or Yarn:

npm i -D @stylify/bundler
yarn add -D @stylify/bundler

Also for the watch mode, we need to run two paralel tasks. This can be solved using concurrently:

yarn add -D concurrently
npm i concurrently

Next, create a file, for example stylify.js:

const { Bundler } = require('@stylify/bundler');

const isDev = process.argv[process.argv.length - 1] === '--w';
const bundler = new Bundler({
  watchFiles: isDev,
  // Optional
  compiler: {
    mangleSelectors: !isDev,
    // https://stylifycss.com/docs/stylify/compiler#variables
    variables: {},
    // https://stylifycss.com/docs/stylify/compiler#macros
    macros: {},
    // https://stylifycss.com/docs/stylify/compiler#components
    components: {},
    // ...
  },
});

// This bundles all CSS into one file
// You can configure the Bundler to bundle CSS for each page separately
// See bundler link bellow
bundler.bundle([
    {
        files: ['./src/**/*.html', './src/**/*.ts'],
        outputFile: './src/styles.css',
    },

    // You can also split css for each component
    // You can map files within the components using content comment option
    // https://stylifycss.com/docs/bundler#files-content-option
    // Stylify takes that option and searches for defined files. If defined file
    // also has an option, id check also those files and so long.
    // This way it maps all files and all dependencies.
    /*
    {
        files: ['./src/app/app.component.*'],
        outputFile: './src/app/app.component.css',
    },
    */
]);

If you don't use splitting and everything will not bundled into the styles.css, then don't forget to add paths to css files.

The last step is to add scripts into the package.json:

"scripts": {
    "dev": "concurrently 'yarn stylify.dev' 'ng serve -c development'",
    "prod": "yarn stylify.build & ng serve",
    "stylify.build": "node stylify.js",
    "stylify.dev": "node stylify.js --w"
}

In production, you will get optimized CSS and mangled html:

<h1 class="font-size:24px color:#dd0031 font-family:arial">
Hello World!
</h1>
.a{font-size:24px}
.b{color:#dd0031}
.c{font-family:arial}

Stackblitz Playground

Go ahead and try Stylify CSS + Angular on Stackblitz.

Configuration

The examples above doesn't include everything Stylify can do:

Feel free to checkout the docs to learn more 💎.

Let me know what you think!

I will be happy for any feedback! The Stylify is still a new Library and there is a lot of space for improvement 🙂.


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Vladimír Macháček


Print Share Comment Cite Upload Translate Updates
APA

Vladimír Macháček | Sciencx (2022-11-28T14:26:12+00:00) Style your Angular website faster with Stylify CSS. Retrieved from https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/

MLA
" » Style your Angular website faster with Stylify CSS." Vladimír Macháček | Sciencx - Monday November 28, 2022, https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/
HARVARD
Vladimír Macháček | Sciencx Monday November 28, 2022 » Style your Angular website faster with Stylify CSS., viewed ,<https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/>
VANCOUVER
Vladimír Macháček | Sciencx - » Style your Angular website faster with Stylify CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/
CHICAGO
" » Style your Angular website faster with Stylify CSS." Vladimír Macháček | Sciencx - Accessed . https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/
IEEE
" » Style your Angular website faster with Stylify CSS." Vladimír Macháček | Sciencx [Online]. Available: https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/. [Accessed: ]
rf:citation
» Style your Angular website faster with Stylify CSS | Vladimír Macháček | Sciencx | https://www.scien.cx/2022/11/28/style-your-angular-website-faster-with-stylify-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.