Git Product home page Git Product logo

auto-minify's Introduction

auto-minify

test workflow

Minifies JS and CSS files.

Quickstart

on: [push]

jobs:
  minify:
    runs-on: ubuntu-latest
    steps:
      - name: check out the repository
        uses: actions/checkout@v4

      - name: auto minify the files
        uses: nizarmah/auto-minify@v3

      - name: auto commit the minified files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "bot: Add auto minified files"

Features

  • Flexibility: Minify JS and CSS files with the engine of your choice.
  • Customization: Specify directories, handle file overwrites, and control traversal depth.
  • Reliability: Continuous integration tests validate functionality and predictability.

Customization

Inputs

Input Description Required Default Value
directory Directory that contains the files you want to minify. false .
output Directory that contains the minified files. false .
overwrite Overwrites the existing files with the minified version. Defaults to false. false false
maxdepth Descend at most levels (a non-negative integer) levels of directories below the starting-points. false
js_engine Specifies which of the supported packages minifies JS files. Supported packages: babel, uglify-js false babel
css_engine Specifies which of the supported packages minifies CSS files. Supported packages: lightning, clean-css false lightning

Important

All paths are relative to the root of the repository.

output defaults to the same directory as directory, unless specified.

maxdepth traverses into all subdirectories by default.

Examples

Overwriting existing files
on: [push]

jobs:
  minify:
    runs-on: ubuntu-latest
    steps:
      - name: check out the repository
        uses: actions/checkout@v4

      - name: replace js and css files with minified ones
        uses: nizarmah/auto-minify@v3
        with:
          overwrite: true

      - name: auto commit the minified files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "bot: Add auto minified files"

Restricting traversal depth
on: [push]

jobs:
  minify:
    runs-on: ubuntu-latest
    steps:
      - name: check out the repository
        uses: actions/checkout@v4

      - name: auto minify files at most 1 level deep
        uses: nizarmah/auto-minify@v3
        with:
          maxdepth: 1

      - name: auto commit the minified files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "bot: Add auto minified files"

Targeting specific directories
on: [push]

jobs:
  minify:
    runs-on: ubuntu-latest
    steps:
      - name: check out the repository
        uses: actions/checkout@v4

      - name: auto minify files in the js directory
        uses: nizarmah/auto-minify@v3
        with:
          directory: 'js'

      - name: auto commit the minified files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "bot: Add auto minified files"

Saving to a different directory
on: [push]

jobs:
  minify:
    runs-on: ubuntu-latest
    steps:
      - name: check out the repository
        uses: actions/checkout@v4

      - name: auto minify files to a different directory
        uses: nizarmah/auto-minify@v3
        with:
          directory: 'assets'
          output: 'mini_assets'

      - name: auto commit the minified files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "bot: Add auto minified files"

Using different engines
on: [push]

jobs:
  minify:
    runs-on: ubuntu-latest
    steps:
      - name: check out the repository
        uses: actions/checkout@v4

      - name: auto minify files with different engines
        uses: nizarmah/auto-minify@v3
        with:
          js_engine: 'uglify-js'
          css_engine: 'clean-css'

      - name: auto commit the minified files
        uses: stefanzweifel/git-auto-commit-action@v5
        with:
          commit_message: "bot: Add auto minified files"

Tip

If you can't find what you're looking for, check our automated tests.

Contributing

Your contributions are welcome! There's no guide yet, but don't hold back.

If it's a bug, please provide a minimal example to reproduce it.

If it's a feature, please provide a use case for it.

If it's a pull request, please provide a description and a test case for it.

Cheers!

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

We also provide major version tags to make it easier to always use the latest release of a major version. For example, you can use nizarmah/auto-minify@v3 to always use the latest release of the current major version.

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

auto-minify's People

Contributors

alexmigf avatar c0pyr1ght avatar nizarmah avatar renelamo avatar ronan-smith avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

auto-minify's Issues

Help with an error

I keep receiving this error halfway through the build:
image

Here's my yml setup:

name: Auto Minifier CSS

on: push

jobs:

  build:
    runs-on: ubuntu-latest

    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2
      - name: Auto Minify
        uses: nizarmah/[email protected]
        with:
          overwrite: false
          directory: .
          maxdepth: 20
      - name: Auto commit minified files
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          commit_message: "Github Action: Auto Minified JS and CSS files"
          branch: ${{ github.ref }}

Could somebody diagnose?

Option to overwrite source files (instead of creating new .min files) when not committing back to repo

I'd really like to use this action as part of my simple deployment workflow for deploying a static hand-coded website; currently the workflow just checks out the source code, connects to the server via SFTP, and then transfers across any files that have changed - no files are written back to the repository.

The problem is all references in the project point to source files without the .min extension so when this action creates new files with the .min extension, the minified files aren't loaded by the page so the minification is pointless - I'm not using any other preprocessors so I can't dynamically change the reference in the HTML file.

Would it be possible to add an option to overwrite the existing source files with the minified versions instead of creating new copies with the .min extension, providing that the option to auto-commit back to the repo is not used?

Unexpected token `const`

Minifaction process fails with Unexpected token: keyword «const» if const is used in a file that is should be minified.

Example:

const url = "https://example.de";

Update readme examples

The version constraints in the readme examples are a little dated or not ideal I would suggest to make these changes:

stefanzweifel/[email protected]

to:

stefanzweifel/git-auto-commit-action@v4

and your own:

nizarmah/auto-minify@master

I would change to

nizarmah/auto-minify@v2

(I would consider master to be more like the bleeding edge for people who need quick access to an unreleased fix, but stable releases more suitable for most people)

Minify HTML files

Hi,

Would it be possible to extend minify to HTML also? As I understand npm minify supports minify of html files.

Expected format {org}/{repo}[/path]@ref. Actual 'nizarmah/auto-minify'

Hi,

I'm trying to use the simplest form on my project. Even though I'm doing everything right (at least for me), I'm getting this error:

Expected format {org}/{repo}[/path]@ref. Actual 'nizarmah/auto-minify'

My file:

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so auto-minify job can access it
       - uses: actions/checkout@v2

       - name: Auto Minify
         uses: nizarmah/auto-minify

       # Auto commits minified files to the repository
       # Ignore it if you don't want to commit the files to the repository 
       - name: Auto committing minified files
         uses: stefanzweifel/[email protected]
         with:
           commit_message: "Automated: Minified CSS files"
           branch: ${{ github.ref }}

Thanks!

Action Should Create Folder/Directory When It Doesn't Exist

Loving this action, except I can't get it working exactly how I want it in my code. I plan on creating in a development folder, and having Auto Minify output to my production folder, which is then pushed to my gh-pages branch for Github Pages deployment.

When running, I get the following error. I may try and make a PR later, thought I would update here so you're aware.

Minify : /github/workspace/development/assets/plus.js -> /github/workspace/production/assets/plus.min.js
Error: ENOENT: no such file or directory, open '/github/workspace/production/assets/plus.min.js'

Thanks for this, really awesome idea!

CSS minification in :not()

Currently, all spaces in the :not() function are removed, breaking most conditions. Example:

ul > li:not(.class ul > li, .another-class ul > li) {
        display: none;
}

will become :

ul>li:not(.classul>li,.another-classsul>li){display:none;}

Mark action as failed on error in minification process

I think it would be helpful to set the action as failed if for example a Parse error occurs during minification process because the scoped files are not actually minified and therefore the goal not reached.

Several Times I had some minor typos within the files to me minified that lead to a Parse error. Therefore the file was obviously not commited to the repo but the action was always marked as successfull which is very missleading. You have to manually dive through the action logs to discover the failed minification process.

Only minify changed files

Hello, is this possible to minify only changed files?
let's say I have a folder called "js" and inside the js folder I have lot of of js files, is there any way to minify only for changed files?

Handling nested directories

Thank you for making this! How do you recommend handling multiple directories? For example if I have:

js/a
js/b
js/c

Can I do something like directory: 'js/*'?

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.