Git Product home page Git Product logo

webcompiler's Introduction

Web Compiler

A Visual Studio extension that compiles LESS, Sass Stylus, JSX, ES6 and CoffeeScript files.

Build status

Download the extension at the VS Gallery or get the nightly build

See the changelog for changes and roadmap.

Features

  • Compilation of LESS, Scss, Stylus, JSX, ES6 and (Iced)CoffeeScript files
  • Saving a source file triggers re-compilation automatically
  • Specify compiler options for each individual file
  • Error List integration
  • MSBuild support for CI scenarios
  • Minify the compiled output
  • Minification options for each language is customizable
  • Shows a watermark when opening a generated file
  • Shortcut to compile all specified files in solution
  • Task Runner Explorer integration
  • Command line interface
  • Integrates with Web Analyzer

Getting started

Right-click any .less, .scss, .styl, .jsx, .es6 or .coffee file in Solution Explorer to setup compilation.

Compile file

A file called compilerconfig.json is created in the root of the project. This file lets you modify the behavior of the compiler.

Right-clicking the compilerconfig.json file lets you easily run all the configured compilers.

Recompile

Compile on save

Any time a .less, .scss, .styl, .jsx, .es6 or .coffee file is modified within Visual Studio, the compiler runs automatically to produce the compiled output file.

The same is true when saving the compilerconfig.json file where all configured files will be compiled.

Compile on build / CI support

In ASP.NET MVC and WebForms projects you can enable compilation as part of the build step. Simply right-click the compilerconfig.json file to enable it.

Compile on build

Clicking the menu item will prompt you with information about what will happen if you click the OK button.

Compile on build prompt

A NuGet package will be installed into the packages folder without adding any files to the project itself. The NuGet package contains an MSBuild task that will run the exact same compilers on the compilerconfig.json file in the root of the project.

Compile all

You can run the compiler on all compilerconfig.json files in the solution by using the keyboard shortcut Shift+Alt+Y or by using the button on the top level Build menu.

Compile all

Task Runner Explorer

Get a quick overview of the files you've specified or execute a compilation directly in Task Runner Explorer.

Task Runner Explorer

You can even set bindings so that compilation happens automatically during certain Visual Studio events, such as BeforeBuild and Project Open.

Task Runner bindings

Error list

When a compiler error occurs, the error list in Visual Studio will show the error and its exact location in the source file.

Error List

Source maps

Source maps are supported for .scss files only for now, but the plan is to have source map support for all languages. Web Compiler differs from it's predecesor, Web Essentials, in that it inlines a base64 encoded version of the map in the generated .css file rather than producing a separate .map file.

compilerconfig.json

The extension adds a compilerconfig.json file at the root of the project which is used to configure all compilation.

Here's an example of what that file looks like:

[
  {
    "outputFile": "output/site.css",
    "inputFile": "input/site.less",
    "minify": {
        "enabled": true
    },
    "includeInProject": true,
    "options":{
        "sourceMap": false
    }
  },
  {
    "outputFile": "output/scss.css",
    "inputFile": "input/scss.scss",
    "minify": {
        "enabled": true
    },
    "includeInProject": true,
    "options":{
        "sourceMap": true
    }
  }
]

Default values for compilerconfig.json can be found in the compilerconfig.json.defaults file in the same location.

webcompiler's People

Contributors

achbed avatar alexjustus avatar andrewiggins avatar craigktreasure avatar djanosik avatar drphrozen avatar duncansmart avatar falahati avatar gproulx avatar iouri-s avatar jkewley avatar jws305 avatar kiasyn avatar krusen avatar madskristensen avatar markvantilburg avatar michalstanko avatar mlorbetske avatar outlivier avatar paulvrugt avatar samfromlv avatar sguryev avatar winterific 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

webcompiler's Issues

scss compile error using includeInProject and under TFS source control

Compiling file.scss files gives a dialog error saying something like "compilerconfig.json is wrong format". A unchecked-out file.css under source control (readonly file) seems to cause it.

Work around: setting all "includeInProjects" to "false" in compilerconfig.json, and removing all file.css from source control (TFS in my case). Or manually checking out all *.css and *.min.css in compilerconfig.json.

Crashing on compile

The extension was working fine. I made some minor changes to some of the files (moved some content around, removed a file, renamed another file) and added @import (reference) ... lines to the top of some of the files and now the extension crashes every time it tries to compile. It turns out, I missed updating an import statement in my main .less file, so the compiler was failing with a file not found error, but that was causing the extension to crash Visual Studio.

File globbing

It feels like this should support file globs. I have about 12 LESS files in a pages directory that all need their own individual compiled files. Right now I think I need to manually add a JSON entry for each one. I'd rather do something like:

  {
    "files": "Content/pages/*.less",
    "minify": {
      "enabled": false
    },
    "includeInProject": true,
    "sourceMap": false,
    "options": {}
  },

Support for F12

It was great to jump to less file just by pressing F12 inside the cshtml file against class name, please add that to Web Compiler.

Compiling mixins

Hi, I have come across a bug in the compilation of a mixin. I am using a loop like this:

.height-loop(@height, @divider) when (@divider > 0) {
    &.h-@{divider} {
        height: @height * @divider;
    }
    .height-loop(@height, (@divider - 1));
}

and it seems to be ignoring the & on the second line so when it creates the css it produces code like

.class .h-1 { 

and not

.class.h-1 {

Note: This worked correctly in VS2013 and the old version of web essentials.

Thanks!

Less compiler version ?

Hi,
Would it be possible to update the LESS compiler ? It seems it's still in LESS version 1.5.0.
That would be great because it introduces a lot of new enhancements!
Thx,
Nico.

PS: I would also thank you for your amazing work on web essentials & compiler. I do understand your choices. Bravo!

error when converting from less to css

background: rgb(0, 0, 0) url("/content/images/welcome-background2.jpg") no-repeat fixed 120% 50% / 50% auto !important;

 becomes

background: black url("/content/images/welcome-background2.jpg") no-repeat fixed 120% 1% auto !important;

Addding a file to compiler via context menu fails (directory name with spaces)

Create a less file in a directory that has a space in the name causes failure in compilation.
create a path ~/styles/with spaces/myStyles.less
Right click and select Compile file.
the urls are added to the compilerconfig.json, however it doesnt handle the spaces correctly.

{
    "outputFile": "styles/with%20spaces/myStyles.css",
    "inputFile": "styles/with%20spaces/myStyles.less",
    ....
}

Simply replacing the %20 with a space allows compilation to continue.

Automatically select the file's folder when compiling

Not sure why, but when you right-click a file and choose "Compile file...", it opens up a dialog with the Project root folder selected, not the actual file's folder...

That ain't right, right?

Right! 👍 😄

Thanks!

Source map reference wrong?

I'm using the following configuration:

{
  "outputFile": "Content/licenses/Demo/styles.css",
  "inputFile": "Content/licenses/Demo/styles.scss",
  "minify": {
    "enabled": false
  },
  "includeInProject": true,
  "sourceMap": true,
  "options": {}
}

The generated .css file contains the following at the end:

/*# sourceMappingURL=styles.scss.map */

However, the generated source map has the filename styles.css.map. (Note the different extension.)

Generate (gulp|grunt)file.js

It would be nice to be able to right click on the compilerconfig.json file and have it generate an equivalent (gulp|grunt)file.js file.

LESS mixins with properties as parameter

I can't get this mixin to compile using WebCompiler:

.pxToRem(@property, @px) {
    @{property}: unit(@px, px);
    @{property}: unit(@px / 10, rem);
}

body {
    color: aliceblue;
    .pxToRem(font-size; 16);
} 

It should be perfectly valid LESS, but I'm receiving this error:

(WebCompiler) Expected '}' but found '{' on line 3 in file '...'

Implement preview window

Web Essentials 2013 had a preview window that would show the compiled output side-by-side with the source file. However, the implementation in WE wasn't good enough, so new logic has to be invented for this.

Here are the features it needs:

  1. Shortcut key to show/hide
  2. Keyboard input support
  3. Line numbers
  4. Maintain scroll position after source file save

The dotless compiler is not a suitable replacement for the official lessc compiler

Moving to dotless means a step back in functionality compared to what was offered with Web Essentials and its integration with NodeJS:

  • No support for detached rulesets
  • No support for canon JS-based plugin architecture
  • No support for inline JS expressions
  • No support for inline JS plugin references (2.5.0 @plugin keyword)
  • Incomplete, buggy support for the :extend feature
  • Partial implementation of the default function library
  • On functions that are implemented; output that is not compliant with the official Less compiler
  • etc.

The dotless compiler is (on some fronts quite literally) years behind the curve on language features compared to the official Less compiler and switching the WebCompiler package to it is a BAD IDEA.

This will lead to headaches with third-party frameworks like Bootstrap, which base themselves on the state of the official compiler. This will lead to user confusion between usage of dotless by the WebCompiler package and usage of lessc with the grunt/gulp/etc. asset pipeline in VS2015 proper.

It is also a kick to the groin for those that have used and become accustomed to the features of the real compiler with WebEssentials 2013; have written nice and clean Less files making use of new language constructs and that now have to either give up on their compilation and preview tooling with VS 2015 or have to face stripping down their code to work with the subpar dotless implementation.

#FFF converted to white on compile

Less file:

.WhiteBackgroundColor
{
    background-color: #FFF;
}

Output (.css file):

.WhiteBackgroundColor {
  background-color: white;
}

Expected output (.css file):

.WhiteBackgroundColor {
  background-color: #FFF;
}

Compile File... default file name

Clicked on a .less file.

It would be very good if the suggested file name could have the required extension (.css) added by default. Currently it shows the name of the HTML file, and offers to overwrite it if I don't add the extension.

Can add the same file more than once

Right clicking on a .less file and selecting "Compile file..." will add it to the compilerconfig.json file. Repeating that process allows me to compile the file again, which results in a second entry in the compilerconfig.json file. It seems like I should only be able to add the file once.

a problem with the sass compiler that is used

Hi Mads,

First of all, I love this extension!

But there seems to be a problem when I try to compile the following Sass,

I have a list looking somthing like this:

$mdi-list-icons: ('navigation-menu': '\e8a1', ...);

And my loop through the list looks like this:

@each $mdi-icon-name, $mdi-icon-value in $mdi-list-icons {
  .#{$mdi-prefix}#{$mdi-icon-name}:before {
    content: $mdi-icon-value;
  }
}

the problem is, that the result looks like this: (which the font can't interpret)

.mdi-navigation-menu:before {
  content: ''; }

Where it should look like this:

.mdi-navigation-menu:before {
  content: '\e8a1'; }

The sass file is from: http://materializecss.com/

And they write that this bug should have been fixed in Sass v. 3.3.x. is it possible to update it?
Because their fix gives the same error

Error compiling on build

Hi, I'm getting the following error "Expected '}' but found 'n' on line 272 in file ...\tables.less". The thing is, if I compile that file alone (by modifying it of by selecting "Recompile all files" over the compilerconfig.json) I don't get any errors and the file gets correctly compiled.

That line (272 of table.less) has this code:

animation-name: bounce_loadingProgress;

I'm not sure what other information might be useful for you...

Hex code are replaced by color name

I am using Bootstrap 3 and I noticed that Hex Color code gets replaced by color name.
For example: normalize.less file has below class

mark {
  background: #ff0;
  color: #000;
}

and in CSS it gets compiled to

mark {
  background: yellow;
  color: black;
}

I have gone thru existing issues but wasn't able to find any existing issue. Also this doesn't happen for all the cases for example:

pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  } 

gets compiled to

pre,
 blockquote {
    border: 1px solid #999999;
    page-break-inside: avoid;
}

LESS compiler w/ StrictMath breaks negative numbers

I don't see this problem with my Grunt task that runs at build-time (also using StrictMath), only with compile-on-save via Web Compiler (which I use to enable BrowserLink to do its thing when I CTRL+S).

Problem is that this in my .less file:
top: -100px
becomes this in the CSS:
top: - 100px

This is invalid CSS and isn't accepted by browsers.

Error when saving .less file

I have Visual Studio 2015 Enterprise (rtm), and a web application started in VS 2013 (so it's not using new ASP.NET 5 features). I just started trying to use LESS, so I installed Web Essentials 2015 and Web Compiler.

I renamed Site.css to Site.less and added it for compilation (right-click, chose Compile File, told it to save back to the same folder as the .less file).

Now when I save it, I get an error dialog:
image

The odd thing is that it does re-generate the css file. Also, right-clicking the .less file in solution explorer and choosing "recompile file" works without any error dialog.

Here's my compilerconfig.json file, which I have not modified myself:

    [
      {
        "outputFile": "Content/Site.css",
        "inputFile": "Content/Site.less",
        "minify": {
          "enabled": true
        },
        "includeInProject": true,
        "sourceMap": false,
        "options": {}
      }
    ]

Saving file causes all files to recompile.

When saving an individual file, I am seeing all my of my less files in the compilerconfig.json being compiled. I have quite a few less files and having it go through all my files seems like an unnecessary waste.

Appears in VS2013 NuGet library as available package but doesn't work

I know this works with VS2015 RC so when I saw it was available for 2013 Update 4 I immediately downloaded it. However there are no right-menus or or sign of functionality.

So what does this mean? Did you or Microsoft accidentally flag it as available for 2013 or is 2013 now supported (then how do I get it to work)?

Unable to compile lesshat

As the title says, the extension is unable to compile lesshat. I know that this might be a dotless issue but right now I'm unable to get a binary compiled version of it. Please close the issue if that's the case.

Visual Studio 2013

This looks like an excellent extension. Is there any chance it can be enabled for Visual Studio 2013?

Support file renames

This may be out of scope for this extension, but what would be really nice is if it could detect file renames and automatically update import statements (or the equivalent include type statement) with the new name.

For example, I have a main.less which looks like:

@import "file`.less";
@import "file1.less";
@import "file2.less";

If I rename file1.less to buttons.less, it would be great if the extension could detect that and automatically update the @import "file1.less" line to @import "buttons.less".

Error when building in VSO

When doing a build in VSO I receive the following error:

d:\a\src\packages\BuildWebCompiler.1.0.73\build\BuildWebCompiler.targets (7): Syntax error in d:\a\src\Dashboard.Web\compilerconfig.json

Here is what is in my complerconfig.json

[
{
"outputFile": "Content/Dashboard.css",
"inputFile": "Content/Dashboard.less",
"minify": {
"enabled": true
},
"includeInProject": true,
"sourceMap": false,
"options": {}
}
]

I'm using version 1.0.73 of WebCompiler

Thanks,
Matt

LESS: Including another style set generates invalid CSS

In Web Essentials 2013, this wasn't an issue, but when I use the new Web Compiler in VS2015, I'm trying to use this code to copy styles from one element to another (using Bootstrap 3.x).

My Site.less file

@import (reference) "Bootstrap/mixins/alerts.less";
@import (reference) "Bootstrap/alerts.less";
.validation-summary-errors {
  .alert; .alert-danger;
}

Bootstrap/alerts.less

.alert {
  padding: @alert-padding;
  margin-bottom: @line-height-computed;
  border: 1px solid transparent;
  border-radius: @alert-border-radius;

  // Headings for larger alerts
  h4 {
    margin-top: 0;
    // Specified for the h4 to prevent conflicts of changing @headings-color
    color: inherit;
  }

  // Provide class for links that match alerts
  .alert-link {
    font-weight: @alert-link-font-weight;
  }

  // Improve alignment and spacing of inner content
  > p,
  > ul {
    margin-bottom: 0;
  }

  > p + p {
    margin-top: 5px;
  }
}
// ... skipping
.alert-danger {
  .alert-variant(@alert-danger-bg; @alert-danger-border; @alert-danger-text);
}

Bootstrap/mixins/alert.less:

.alert-variant(@background; @border; @text-color) {
  background-color: @background;
  border-color: @border;
  color: @text-color;

  hr {
    border-top-color: darken(@border, 5%);
  }
  .alert-link {
    color: darken(@text-color, 10%);
  }
}

Site.css Output

This invalid CSS gets put at the very top of the generated file.

 {
  margin-top: 0;
  color: inherit;
}
 {
  font-weight: bold;
}
 {
  margin-bottom: 0;
}
 {
  margin-top: 5px;
}
 {
  border-top-color: #e4b9c0;
}
 {
  color: #843534;
}

I've also run into an issue where the file doesn't compile, but I don't get any sort of message, and nothing in the Output window I can see.

Suggestion: post-processor

Add a way to configure an executable that will run after the compilation has ran. In this way, I can add autoprefixer again (running from node, of course).
Maybe you can add this option to the bundler too (to run between bundling and minification).

Nothing compiled... Missing steps in "Getting started"?

Hi!
I installed the extension. Right clicked and chose "Compile file" on all my less-files.
They were all added to the compilerconfig.json in project root, as described.
But nothing gets compiled.

  • Editiing and saving one of the less files does nothing.
  • Right-clicking compilerconfig.json and choosing "Re-compile all files" does nothing.

css-files are not updated and no error messages pop up anywhere.

Is there some pre-requisite not mentioned in the "Getting started"-section?

Less strictMath option doesn't seem to work

I have the strictMath option set to true, but my css is still coming out wrong. Using 1.0.64 and i don't get any errors when saving either the less or the config files.

compilerconfig.json

[
    {
        "includeInProject": true,
        "inputFile": "file.less",
        "minify": {
            "enabled": true
        },
        "options": {
            "strictMath": true
        },
        "outputFile": "file.css"
    }
]

file.less

...
.class-name {
    height: calc(85% - 60px);
}
...

file.css - actual

...
.class-name {
    height: calc(25%);
}
...

file.css - expected

...
.class-name {
    height: calc(85% - 60px);
}
...

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.