less-loader
Advanced tools
Comparing version 0.7.4 to 0.7.5
@@ -21,2 +21,3 @@ /* | ||
var loaderContext = this; | ||
var query = loaderUtils.parseQuery(this.query); | ||
var cb = this.async(); | ||
@@ -32,3 +33,3 @@ var errored = false; | ||
}; | ||
var moduleRequest = loaderUtils.urlToRequest(url, currentFileInfo.rootpath); | ||
var moduleRequest = loaderUtils.urlToRequest(url, query.root); | ||
@@ -87,3 +88,3 @@ if(cb) { | ||
}); | ||
} | ||
}; | ||
@@ -97,3 +98,3 @@ function updateFileInfo(fileInfo, rootContext, filename) { | ||
function normalizePath(path) { | ||
if (path.sep === "\\") { | ||
if(path.sep === "\\") { | ||
path = path.replace(backslash, "/"); | ||
@@ -100,0 +101,0 @@ } |
{ | ||
"name": "less-loader", | ||
"version": "0.7.4", | ||
"version": "0.7.5", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -15,3 +15,2 @@ "description": "less loader module for webpack", | ||
"mocha": "^1.18.2", | ||
"less": "^1.5", | ||
"webpack": "^1.1.8", | ||
@@ -18,0 +17,0 @@ "raw-loader": "^0.5.1", |
@@ -37,4 +37,30 @@ # less loader for webpack | ||
## Note on imports | ||
webpack provides an [advanced mechanism to resolve files](http://webpack.github.io/docs/resolving.html). The less-loader stubs less' `fileLoader` and passes all queries to the webpack resolving engine. Thus you can import your less-modules from `node_modules` or `bower_components`. Just prepend them with a `~` which tells webpack to look-up the [`modulesDirectories`](http://webpack.github.io/docs/configuration.html#resolve-modulesdirectories) | ||
```css | ||
@import "~bootstrap/less/bootstrap"; | ||
``` | ||
It's important to only prepend it with `~`, because `~/` resolves to the home-directory. webpack needs to distinguish `bootstrap` from `~bootstrap` because css- and less-files have no special syntax for importing relative files: | ||
```css | ||
@import "file"; | ||
``` | ||
is the same as | ||
```css | ||
@import "./file"; | ||
``` | ||
## Contribution | ||
Don't hesitate to create a pull request. Every contribution is appreciated. In development you can start the tests by calling `npm test`. | ||
The tests are basically just comparing the generated css with a reference css-file located under `test/css`. You can easily generate a reference css-file by calling `node test/helpers/generateCss.js <less-file-without-less-extension>`. It passes the less-file to less and writes the output to the `test/css`-folder. | ||
## License | ||
MIT (http://www.opensource.org/licenses/mit-license.php) |
@@ -6,6 +6,9 @@ "use strict"; | ||
var webpack = require("webpack"); | ||
var enhancedReq = require("enhanced-require")(module); | ||
var enhancedReqFactory = require("enhanced-require"); | ||
var fs = require("fs"); | ||
var CR = /\r/g; | ||
var resolveBowerComponents = { | ||
modulesDirectories: ["bower_components"] | ||
}; | ||
@@ -18,9 +21,17 @@ function readCss(id) { | ||
it(name, function (done) { | ||
var css = readCss(id); | ||
var expectedCss = readCss(id); | ||
var lessFile = "raw!" + | ||
path.resolve(__dirname, "../index.js") + "!" + | ||
path.resolve(__dirname, "./less/" + id + ".less"); | ||
var actualCss; | ||
var config = { | ||
resolve: id === "imports-bower"? resolveBowerComponents : {} | ||
}; | ||
var enhancedReq = enhancedReqFactory(module, config); | ||
// run synchronously | ||
enhancedReq(lessFile).should.eql(css); | ||
actualCss = enhancedReq(lessFile); | ||
// writing the actual css to output-dir for better debugging | ||
fs.writeFileSync(__dirname + "/output/" + name + ".sync.css", actualCss, "utf8"); | ||
actualCss.should.eql(expectedCss); | ||
@@ -30,2 +41,3 @@ // run asynchronously | ||
entry: lessFile, | ||
resolve: config.resolve, | ||
output: { | ||
@@ -47,3 +59,8 @@ path: __dirname + "/output", | ||
delete require.cache[path.resolve(__dirname, "./output/bundle.js")]; | ||
require("./output/bundle.js").should.eql(css); | ||
actualCss = require("./output/bundle.js"); | ||
// writing the actual css to output-dir for better debugging | ||
fs.writeFileSync(__dirname + "/output/" + name + ".async.css", actualCss, "utf8"); | ||
actualCss.should.eql(expectedCss); | ||
done(); | ||
@@ -56,3 +73,4 @@ }); | ||
test("should compile simple less without errors", "basic"); | ||
test("should resolve all imports of less-files", "imports"); | ||
test("should resolve all imports", "imports"); | ||
test("should resolve all imports of bower dependencies", "imports-bower"); | ||
test("should transform urls", "url-path"); | ||
@@ -59,0 +77,0 @@ test("should transform urls to files above the current directory", "folder/url-path"); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12985
5
26
284
66
4
1