GithubHelp home page GithubHelp logo

huasofoundries / systemjs-less-plugin Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 11.0 2.58 MB

Translates less on the browser, builds less during build

License: MIT License

JavaScript 79.83% Makefile 5.26% CSS 14.91%
systemjs jspm less plugin-css

systemjs-less-plugin's Introduction

systemjs-less-plugin

Translates less on the browser, inlines CSS conversion during build.

npm Code Climate Travis CI Codacy Badge

This SystemJS plugin provides in-browser compilation of less stylesheets to regular CSS styles, as well as precompilation at the build stage when bundling your project with JSPM.

It depends (of course) on {Less} but you don't need to worry about it. We have it bundled along this loader plugin. It also depends on plugin-css and, again, you don't need to worry about that, because it'll be installed along system-less-plugin.

Installing

To use this plugin, install it with jspm like so:

jspm install less

Then, in your jspm.config file, add less as the loader for less files (duh!):

SystemJS.config({
  paths: {...}
  map: {...}
  meta: {
    '*.less': { loader: 'less' }
  }
});

Configuration and options

This plugin is built on top of the CSS plugin base which provides most of its features. As such, system-less-plugin supports the same build options.

Among other features, this includes source maps and generation of separate CSS files.

Import from jspm packages

Adds the ability for less to import from jspm packages (thanks to @fernandogmar based on lixiaoyan/less-plugin-jspm-import )

In less file:

@import "jspm://packagename/path/to/file.less";

or if importing a css file an import option is required:

@import (less) "jspm://packagename/path/to/file.css";

In case npm is down...

It's very uncommon for NPM to be down, but if that's your case or for any other reson you rather use github, then this is the way:

jspm install less=github:huasofoundries/systemjs-less-plugin

License

MIT

systemjs-less-plugin's People

Contributors

fernandogmar avatar ffflabs avatar mikevitik avatar munawwar avatar natergj avatar ppvg avatar pro-nate avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

systemjs-less-plugin's Issues

What about source map?

This is new after recent changes. less-builder.js complains because sourceMap option was changed to false:

Trace: [TypeError: Cannot read property 'toString' of undefined]
    at eval (file:///Users/***/Documents/EP-trunk/jspm_packages/github/HuasoFoundries/[email protected]/less-builder.js:93:13)

When I manually changed sourceMap: false to sourceMap: outputOpts.sourceMaps then this happened:

Trace: { [Error: Cannot find module 'source-map']
  message: 'Cannot find module \'source-map\'',
  stack: 'Error: Cannot find module \'source-map\'\n    at Function.Module._resolveFilename (module.js:336:15)\n    at Function.Module._load (module.js:286:25)\n    at Module.require (module.js:365:17)\n    at require (module.js:384:17)\n    at Object.getSourceMapGenerator (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less-node/environment.js:12:16)\n    at new SourceMapOutput (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/source-map-output.js:25:59)\n    at SourceMapBuilder.toCSS (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/source-map-builder.js:8:31)\n    at ParseTree.toCSS (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/parse-tree.js:33:47)\n    at /Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/render.js:31:40\n    at /Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/parse.js:63:17\n    at Object.finish [as _finish] (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/parser/parser.js:183:28)\n    at Object.ImportVisitor._onSequencerEmpty (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/visitors/import-visitor.js:35:14)\n    at ImportSequencer.tryRun (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/visitors/import-sequencer.js:50:14)\n    at /Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/visitors/import-sequencer.js:19:25\n    at fileParsedFunc (/Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/import-manager.js:50:17)\n    at /Users/***/Documents/EP-trunk/jspm_packages/github/less/[email protected]/lib/less/import-manager.js:113:21' }
    at eval (file:///Users/***/Documents/EP-trunk/jspm_packages/github/HuasoFoundries/[email protected]/less-builder.js:93:13)

Loader not working

Hi,

I am trying to use it in my angular2 app, but it seems that the less files are not loaded and I can't understand why.

Any help please?

How to configure the build options [I am using jspm 0.17.0-beta.38]

Hi !

I read that "system-less-plugin supports the same build options" as plugin-css. But how exactly they can be set. I am doing this:

SystemJS.config({
    rootURL: './public'
});

But on building it seems it still looks for the files in the wrong folder. For example /my-file.less it is not resolved as ....../public/my-file.less. It keeps the the same path '/', that is obviously wrong.

Am I missing something?

Wrong url processing

I try to bundle simple tmp.less file

.drop-down-icon {
    background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAABISURBVDhPY2hoaPhPLgZrBgIGUvGoZihOTEzEGrIgcWR1IDGsNqMbgK4RhHFqBmGYAdg0gjBezSCMSyMIE9SMDw91zeThhv8Ami96gQcIp6MAAAAASUVORK5CYII=);
}

In config I add
meta: { "tmp": { deps: [ "tmp.less!less" ] } },
After bundling:
jspm bundle tmp
I get a wrong result for icon url. Instead of original url(data.. I have url(D:\tmp\LessUrl/data...

(function(c){var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));})
(".drop-down-icon {\n  background-image: url(D:\\tmp\\LessUrl/data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAA71pVKAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAABISURBVDhPY2hoaPhPLgZrBgIGUvGoZihOTEzEGrIgcWR1IDGsNqMbgK4RhHFqBmGYAdg0gjBezSCMSyMIE9SMDw91zeThhv8Ami96gQcIp6MAAAAASUVORK5CYII=);\n}\n");

lessPlugin.zip

Resolve package paths

The only way I could find to reference a package that contains a less file is to use something like @import '../../jspm_packages/github/distros/[email protected]/bootstrap/index.less'. Which is obviously going to easily end up in a maintenance nightmare down the road.

The import statement in the typescript plugin for example properly resolves the package, without any version information attached, unless the paths start with . or ...

Is there a way to specify the paths in a similar fashion with this plugin, e.g. @import 'bootstrap-less/bootstrap/index.less? Thanks.

ReferenceError: window is not defined

Hi there and thanks for this plugin.

Environment:
jspm: 0.17.0-beta.42
systemjs: 0.20.14
systemjs-builder: 0.16.9
systemjs-less-plugin: 2.0.0

When I try to build a static js with systemjs-builder I get error:

ReferenceError: window is not defined

I've debugged bit and it seems that this condition is not met, because this.builder is undefined and that's why less.browser.js is used also in node environment. Not sure why.

v2.0.0 - question about overriding/reusing Bootstrap vars/mixins

Hello,

thank you for your work on this plugin. I see it's about to become an official SystemJS plugin for LESS.

A lot has changed in the source code. The plugin is now based on standard workflow introduced by css-plugin-base. Since last version of this plugin actual LESS compilation has moved to translate() function because this is the API.

Unfortunately this broke bundling in my project. I deal with legacy Bootstrap v2 styles. I need to override certain core Bootstrap variables and mixins. This was possible before because that version of the plugin concatenated all LESS files before compiling and rebased @import and url calls. The new version also rebases correctly. But I have no access to core Bootstrap vars in my project styles. And I can't simply @import (reference) core bootstrap.less because its path varies.

There are LESS plugins that can resolve jspm modules' paths like https://github.com/sebasrodriguez/jspm-less.

This way I'm able to @import (reference) bootstrap.less in my project styles. But unfortunately SystemJS rebasing of css urls stops working.

Then I came with other solution: I created a Gulp task that appends an @import to my project overrides to the end of bootstrap.less in its normal location before running jspm bundle. This works but LESS needs to know how to resolve jspm paths. If I manually prepend

var JspmLess = System._nodeRequire("jspm-less");

to https://github.com/HuasoFoundries/systemjs-less-plugin/blob/master/src/less.js and add it later during compilation:

less.render(style, {
...
plugins: [new JspmLess()]
...
});

then jspm is able to compile and bundle LESS. My project styles that are scoped in view components and use some bootstrap vars or mixins must only have @import (reference) bootstrap.less prepended.

But https://github.com/HuasoFoundries/systemjs-less-plugin/blob/master/src/less.js is supposed to run in browser and in Node. The System._nodeRequire doesn't work in browser when there's a need to dynamically load less files.

I don't know if I approach the problem correctly. My suggestion is to include JSPM path resolution for LESS directly in the systemjs-less-plugin.

Bundling .less files without compilation?

I've been trying to bundle up the .less files contained in the bootstrap-less package, with no success so far. For example the command jspm bundle bootstrap-less/bootstrap/index.less! dist/external-deps-bootstrap.js, seems to compile the bootstrap less files. However, for dev purposes, if a .less file in the app references any .less file from bootstrap, all the .less files get downloaded again. Is it possible to ignore the compilation of these files but still bundle them? Would then a a second config be required to be referenced from the app in order to perform the compilation in the browser?

The config is below:

SystemJS.config({
  paths: {
    "github:": "jspm_packages/github/",
    "npm:": "jspm_packages/npm/",
    "web-client/": "ClientSrc/",
  },
  devConfig: {
  transpiler: "plugin-typescript",
  typescriptOptions: {
    "tsconfig": true
  },
  packages: {
    "web-client": {
      "main": "modules/main.dev.ts",
      "defaultExtension": "ts",
      "meta": {
        "*.ts": {
          "loader": "plugin-typescript"
        },
        "*.less": {
          "loader": "less"
        },
        "*.css": {
          "loader": "less"
        }
      }
    }
  },
 [... mappings ,etc.]
});

Any help would be appreciated. Thanks.

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.