All Projects → excubo-ag → WebCompiler

excubo-ag / WebCompiler

Licence: Apache-2.0 license
No description or website provided.

Programming Languages

C#
18002 projects
SCSS
7915 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to WebCompiler

Fontmin Webpack
Minifies icon fonts to just the used glyphs.
Stars: ✭ 93 (-10.58%)
Mutual labels:  minification
clean-css
Fast and efficient CSS optimizer for node.js and the Web
Stars: ✭ 4,048 (+3792.31%)
Mutual labels:  minification
luasrcdiet
Compresses Lua source code by removing unnecessary characters (updated fork of http://luasrcdiet.luaforge.net/)
Stars: ✭ 60 (-42.31%)
Mutual labels:  minification
Wpgulp
An advanced Gulp workflow for WordPress development with extensive documentation. Used by 40,000+ themes and plugins.
Stars: ✭ 1,733 (+1566.35%)
Mutual labels:  minification
Image Shrinker
App for macOS. Minify your images and graphics with just one drop. Autorenamed in the same place where it comes from. Immediately!
Stars: ✭ 217 (+108.65%)
Mutual labels:  minification
MinifyAll
A 𝗩𝗦𝗖𝗼𝗱𝗲 𝗺𝗶𝗻𝗶𝗳𝗶𝗲𝗿 for JS, JSON/C, CSS, and HTML, you will love its simplicity! 🌟 𝘾𝙤𝙢𝙥𝙧𝙚𝙨𝙨 and 𝙜𝙯𝙞𝙥 files and folders 📦 Reduce your bundle and file sizes with lightning speed ⚡
Stars: ✭ 54 (-48.08%)
Mutual labels:  minification
Jekyll Minibundle
A minimalistic asset bundling plugin for Jekyll
Stars: ✭ 65 (-37.5%)
Mutual labels:  minification
DynamicProto-JS
Generates dynamic prototype methods for JavaScript objects (classes) by supporting method definition within their "class" constructor (like an instance version), this removes the need to expose internal properties on the instance (this) which results in better code minfication and therefore improved load times for your users.
Stars: ✭ 16 (-84.62%)
Mutual labels:  minification
Static Html Webpack Boilerplate
🔮 modern tooling for old-school static webpage development
Stars: ✭ 226 (+117.31%)
Mutual labels:  minification
MinifyAllCli
📦 A lightweight, simple and easy npm tool to 𝗺𝗶𝗻𝗶𝗳𝘆 JSON/C, HTML and CSS! Also known as MinifyAll core! ⭐ Usable as 𝑪𝑳𝑰 tool or 𝒊𝒎𝒑𝒐𝒓𝒕𝒂𝒃𝒍𝒆 in TS/JS as a 𝑴𝑶𝑫𝑼𝑳𝑬 🥰
Stars: ✭ 21 (-79.81%)
Mutual labels:  minification
Yii2 Minify View
Yii2 View component with minification css & js
Stars: ✭ 186 (+78.85%)
Mutual labels:  minification
Webpack Tricks
Tips and tricks in using Webpack
Stars: ✭ 2,364 (+2173.08%)
Mutual labels:  minification
rollup-plugin-html
Import HTML files as strings in rollup build
Stars: ✭ 36 (-65.38%)
Mutual labels:  minification
Static Site Boilerplate
A better workflow for building modern static websites.
Stars: ✭ 1,633 (+1470.19%)
Mutual labels:  minification
pdfminify
PDF minifier that allows removing duplicate data, re-compresses images, creation of PDF/A-1b and digital PDF signing
Stars: ✭ 46 (-55.77%)
Mutual labels:  minification
Esbuild Loader
⚡️ Speed up your Webpack build with esbuild
Stars: ✭ 1,245 (+1097.12%)
Mutual labels:  minification
bootstrap-4-boilerplate
Basic Bootstrap 4 Starter Template
Stars: ✭ 50 (-51.92%)
Mutual labels:  minification
CSharp-Minifier
Library for C# code minification based on NRefactory. That is lib for spaces, line breaks, comments removing, reduction of identifiers name length and so on in C# code.
Stars: ✭ 38 (-63.46%)
Mutual labels:  minification
silencio
Silencio is a Java library for transforming and converting XML, JSON, YAML, Properties and other formats. It is applicable for most operations such as obfuscation, encryption, minimisation (minifying), anonymous. Library is fully customizable and extensible.
Stars: ✭ 23 (-77.88%)
Mutual labels:  minification
source-map-unpack
Unpack 🛍 your JS source maps 🗺 to original files and folders.
Stars: ✭ 115 (+10.58%)
Mutual labels:  minification

Excubo.WebCompiler

Nuget Nuget GitHub

Excubo.WebCompiler is a dotnet global tool that compiles Scss files (other languages on the road map, see how to contribute).

This project is based on madskristensen/WebCompiler. However, the dependency to node and the node modules have been removed, to facilitate a pure dotnet core implementation. As a benefit, this implementation is cross-platform (x64 linux/win are tested, please help by testing other platforms!).

⚠️ A common mistake is to add the package Excubo.WebCompiler as a nuget package reference to a project (e.g. by installing it via the nuget package manager in Visual Studio). This does not work! Instead, one needs to install it as a dotnet tool. See the "Getting started" section further down on this page.

Features

  • Compilation of Scss files
  • Dedicated compiler options for each individual file
  • Detailed error messages
  • dotnet core build pipeline support cross-platform
  • Minify the compiled output
  • Minification options for each language is customizable
  • Autoprefix for CSS

Changelog

Changes in version 3.3.Y

Breaking Change / Warning: This change removes the key of IgnoreFolders and IgnoreFiles per 3.2.Y and in favour of an "Ignore" key with support for File Globbing support.

If no Ignore value is defined in the CompilerSettings.json then **/_. (files prefixed with _) will be ignored. If you wish to continue this behaviour and also ignore other patterns, ensure to also include this pattern.

Simply add the following to CompilerSettings.json:

  "CompilerSettings": {
     "Ignore": [ "**/_*.*", "wwwroot/*.scss", "wwwroot/css/specific-file.scss", "wwwroot/_lib/**/*.scss", "bin/**/*", "obj/**/*" ],
  }

Changes in version 3.2.Y

Supports excluding certain files and folders (nb. Sub folders must be specified specifically if wanting to be ignored) when using recursive mode Simply add the following to CompilerSettings.json:

  "CompilerSettings": {
     "IgnoreFolders": ["./wwwroot/", "./bin/", "./obj/", "./wwwroot/sass/"],
     "IgnoreFiles": ["./sass/_variables.scss"]
  }

Changes in version 3.1.Y

Support for netcoreapp3.1 and net5.0 were dropped. The nupkg file was getting outrageously large due to dependencies and duplication across the target frameworks.

Changes in version 3.X.Y

The underlying SASS compiler is changed from libsass to dart-sass. This is a necessary change, as libsass is discontinued. There are two breaking changes when working with the config json file:

  • CompilerSettings.Sass.OutputStyle: The valid values are now Expanded or Compressed. The former default value of Nested is now invalid.
  • The property CompilerSettings.Sass.Precision does not exist anymore.
  "CompilerSettings": {
    "Sass": {
      "IndentType": "Space",
      "IndentWidth": 2,
      "OutputStyle": "Expanded", // was: "Nested"
      //"Precision": 5, // Remove this
      "RelativeUrls": true,
      "LineFeed": "Lf",
      "SourceMap": false
    }
  }

Changes in version 2.4.X

Added support for .NET 5. You will most likely only notice that when using webcompiler in a docker context, but that's covered now as well!

Changes in version 2.3.X

There are now two more options:

  • -o/--output-dir helps to put files into a different folder. See webcompiler -o --help for more details.
  • -p/--preserve disable makes all temporary files disappear (note that this can increase compile time. The default is to keep all temporary files).

Changes in version 2.1.X

  • Previously, running e.g. webcompiler -r without specifying a file and/or folder just returned without any message, warning or error. This is now an error. If the intention is to run in the working directory, use webcompiler -r ..
  • Now writes to stderr instead of stdout where appropriate.
  • Bug fixed: Sass files were not recompiled on change, if that change was to the sass file itself rather than one of its dependencies. Now it correctly recompiles for any change to the file itself or any of its dependencies.

Breaking changes in version 2.0.X

The command line interface has been rewritten from scratch to enable sensible defaults without the need to have a configuration file around. Starting with version 2.0.0, the old compilerconfig.json.defaults is incompatible. A new file can be created with webcompiler --defaults (optional).

Usage:
  webcompiler file1 file2 ... [options]
  webcompiler [options]

Options:
  -c|--config <conf.json>          Specify a configuration file for compilation.
  -d|--defaults [conf.json]        Write a default configuration file (file name is webcompilerconfiguration.json, if none is specified).
  -f|--files <files.conf>          Specify a list of files that should be compiled.
  -h|--help                        Show command line help.
  -m|--minify [disable/enable]     Enable/disable minification (default: enabled), ignored if configuration file is provided.
  -o|--output-dir <path/to/dir>    Specify the output directory, ignored if configuration file is provided.
  -p|--preserve [disable/enable]   Enable/disable whether to preserve intermediate files (default: enabled).
  -r|--recursive                   Recursively search folders for compilable files (only if any of the provided arguments is a folder).
  -z|--zip [disable/enable]        Enable/disable gzip (default: enabled), ignored if configuration file is provided.
  -a|--autoprefix [disable/enable] Enable/disable autoprefixing (default: enabled), ignored if configuration file is provided.

Recommended default usage: webcompiler -r wwwroot.

Roadmap

language support

Due to the removal of node as a dependency (as opposed to madskristensen/WebCompiler), support for languages other than Scss is not yet available. Please get in touch if you want to contribute to any of the following languages, or if you want to add yet another language.

  • LESS
  • Stylus
  • JSX
  • ES6
  • (Iced)CoffeeScript

Getting started

Global

1. Install the tool as dotnet global tool

Excubo.Webcompiler is distributed as a nuget package. You can install it in a command line using

dotnet tool install Excubo.WebCompiler --global
2. Call webcompiler
webcompiler -r wwwroot

Local

It's also possible to use Excubo.Webcompiler as a local tool (ideal for CI environments)

1. Create a new tool manifest
dotnet new tool-manifest
2. Add Excubo.Webcompiler
dotnet tool install Excubo.WebCompiler
3. Restore
dotnet tool restore
4. Usage
dotnet tool webcompiler -h

Build integrations

Command line / terminal

Global

You can simply call webcompiler with the appropriate options, e.g.

webcompiler -r wwwroot
Local
dotnet run tool webcompiler -r wwwroot

or can simply call:

dotnet webcompiler -r wwwroot

MSBuild

You can add webcompiler as a Target in your csproj file. This works cross platform:

  <Target Name="CompileStaticAssets" AfterTargets="AfterBuild">
    <Exec Command="webcompiler -r wwwroot" StandardOutputImportance="high" />
  </Target>

In this example, webcompiler is executed on the folder wwwroot inside your project folder.

Docker

The integration into docker images is as straight-forward as installing the tool and invoking it. However, there's a caveat that some users ran into, which is the use of alpine-based images, such as mcr.microsoft.com/dotnet/sdk:5.0-alpine. Excubo.WebCompiler will not work on this image, as some fundamental libraries are missing on alpine. The alpine distribution is usually intended to create small resulting images. If this is the goal, the best approach is to perform build/compilation operations in a non-alpine distribution, and then finally copy only the resulting files to an alpine based image intended only for execution. Learn more about it here, in Microsoft's usage for dotnet and here, in the docker documentation about multi-stage-build.

MSBuild with execution of webcompiler only if it is installed

Global

This configuration will not break the build if Excubo.WebCompiler is not installed. This can be helpful, e.g. if compilation is only necessary on the build server.

  <Target Name="TestWebCompiler">
    <!-- Test if Excubo.WebCompiler is installed (recommended) -->
    <Exec Command="webcompiler -h" ContinueOnError="true" StandardOutputImportance="low" StandardErrorImportance="low" LogStandardErrorAsError="false" IgnoreExitCode="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
  </Target>

  <Target Name="CompileStaticAssets" AfterTargets="CoreCompile;TestWebCompiler" Condition="'$(ErrorCode)' == '0'">
    <Exec Command="webcompiler -r wwwroot" StandardOutputImportance="high" StandardErrorImportance="high" />
  </Target>

The first target simply tests whether Excubo.WebCompiler is installed at all. The second target then executes webcompiler recursively on the wwwroot folder, if it is installed.

Local

Using dotnet tool locally is quite simple. Unfortunately, there's no easy way to check if tools already exists (as the help always returns error code 0) without a script.

  <Target Name="ToolRestore" BeforeTargets="PreBuildEvent">
      <Exec Command="dotnet tool restore" StandardOutputImportance="high" />
  </Target>

  <Target Name="PreBuild" AfterTargets="ToolRestore">
      <Exec Command="dotnet tool run webcompiler -r wwwroot" StandardOutputImportance="high" />
  </Target>

If you only rely on webcompiler, it may be preferable to use the below PreBuildEvent

 <Target Name="ToolRestore" BeforeTargets="PreBuildEvent">
        <Exec Command="dotnet tool update excubo.webcompiler" StandardOutputImportance="high" />
    </Target>

Which will either:

  • Do nothing if latest is installed
  • Install the latest if either out of date or uninstalled

Compile on save (dotnet watch)

For automatic compilation whenever the content of source files change, add the following to your csproj:

<ItemGroup>
    <!--specify file extensions here as needed-->
    <Watch Include="**\*.scss" />
</ItemGroup>

Run dotnet watch tool run webcompiler with the appropriate options in a terminal, e.g. dotnet watch tool run webcompiler -r wwwroot.

Configuration

If you want to change aspects of the compilation and minification process, create a configuration file, modify it to your needs, and run webcompiler using this config file:

  1. create config file (default file name: webcompilerconfiguration.json)
webcompiler --defaults

The default configuration is

{
  "Minifiers": {
    "GZip": true,
    "Enabled": true,
    "Css": {
      "CommentMode": "Important",
      "ColorNames": "Hex",
      "TermSemicolons": true,
      "OutputMode": "SingleLine",
      "IndentSize": 2
    },
    "Javascript": {
      "RenameLocals": true,
      "PreserveImportantComments": true,
      "EvalTreatment": "Ignore",
      "TermSemicolons": true,
      "OutputMode": "SingleLine",
      "IndentSize": 2
    }
  },
  "Autoprefix": {
    "Enabled": true,
    "ProcessingOptions": {
      "Browsers": [
        "last 4 versions"
      ],
      "Cascade": true,
      "Add": true,
      "Remove": true,
      "Supports": true,
      "Flexbox": "All",
      "Grid": "None",
      "IgnoreUnknownVersions": false,
      "Stats": "",
      "SourceMap": true,
      "InlineSourceMap": false,
      "SourceMapIncludeContents": false,
      "OmitSourceMapUrl": false
    }
  },
  "CompilerSettings": {
    "Sass": {
      "IndentType": "Space",
      "IndentWidth": 2,
      "OutputStyle": "Expanded",
      "RelativeUrls": true,
      "LineFeed": "Lf",
      "SourceMap": false
    }
  },
  "Output": {
    "Preserve": true
  }
}
  1. change config file

Change anything in the generated config file according to your needs. If you need help with the available settings, please refer to the documentation of LibSassHost or NUglify.

  1. Make webcompiler use these options
webcompiler -r wwwroot -c webcompilerconfiguration.json

Error list

When a compiler error occurs, the tool exits with code 1 and displays the error to the console.

Contributing

This project is just starting. You can help in many different ways:

  • File bug reports

    If you find a bug with the tool itself, please file a bug. If the result of compilation is incorrect, please file a bug with the respective library (see the list of libraries), and only file a bug report here, if the version used is outdated.

  • Implement support for a language

    Please submit your pull request for the language that you're implementing. Please make sure that your code is tested.

  • Ask for support of a specific language

    If you would like to see support of a specific language, but can't implement it yourself, please search the issues for the language and leave your +1 vote on the issue, or file a new issue with the name of the language.

Libraries

Excubo.WebCompiler depends on nuget packages for the compilation tasks:

| Language | Library | Comments |----------|---------| | Sass | LibSassHost | | Sass | DartSassHost | WebCompiler 3.X.Y+ | Autoprefix | AutoprefixHost | | CSS/JS | NUglify |

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].