Skip to content

Commit a090e12

Browse files
committed
added val & bundle loader
1 parent bd4017b commit a090e12

8 files changed

Lines changed: 23 additions & 12 deletions

File tree

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ The following loaders are included in webpack:
198198
* `coffee` (default at `.coffee`): Loads coffee-script like javascript
199199
* `css`: Loads css file with resolved imports and returns css code
200200
* `less`: Loads and compiles a less file and returns css code
201+
* `val`: Excutes code as module and consider exports as javascript code
202+
* `bundle`: Wraps request in a `require.ensure` block
201203
* `style`: Adds result of javascript execution to DOM
202-
* (`.css` defaults to `style!css` loader, so all css rules are added to DOM)
203-
* (`.less` defaults to `style!less` loader, so all less rules are added to DOM)
204204
* `script`: Executes a javascript file once in global context (like in script tag), requires are not parsed. Use this to include a library. ex. `require("script!./jquery.min.js")`. This is synchron, so the `$` variable is available after require.
205+
* (`.css` defaults to `style!css` loader, so all css rules are added to DOM)
206+
* (`.less` defaults to `style!css!val!less` loader, so all less rules are added to DOM)
207+
208+
See docs for loader in github repo of the loader.
205209

206210
## TL;DR
207211

lib/buildDeps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function execLoaders(request, loaders, filenames, contents, options, callback) {
134134
} catch(e) {
135135
if(!done) {
136136
done = true;
137-
callback("Loader throwed exeception: " + e);
137+
callback("Loader throwed exeception: " + (e.stack ? e.stack : e));
138138
} else {
139139
if(e.stack) console.error(e.stack);
140140
else console.error(e);

lib/webpack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function webpack(context, moduleName, options, finalCallback) {
134134
options.resolve.loaders.push({test: /\.json$/, loader: "json"});
135135
options.resolve.loaders.push({test: /\.jade$/, loader: "jade"});
136136
options.resolve.loaders.push({test: /\.css$/, loader: "style!css"});
137-
options.resolve.loaders.push({test: /\.less$/, loader: "style!less"});
137+
options.resolve.loaders.push({test: /\.less$/, loader: "style!css!val!less"});
138138

139139
options.events.emit("task", "create ouput directory");
140140
options.events.emit("task", "prepare chunks");

lib/writeSource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ module.exports = function(module, options, toRealId) {
181181
"// module.id = ", module.id, "\n",
182182
"// module.realId = ", module.realId, "\n",
183183
"// module.chunks = ", module.chunks.join(", "), "\n",
184-
"//@ sourceURL=webpack-module://", encodeURI(module.filename).replace(/%5C|%2F/g, "/")
184+
"//@ sourceURL=webpack-module://", encodeURI(module.filename || module.dirname).replace(/%5C|%2F/g, "/")
185185
].join("")),
186186
");"].join("");
187187
}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.3.12",
3+
"version": "0.3.13",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loading of js, json, jade, coffee, css, ... out of the box and more with custom loaders.",
66
"dependencies": {
@@ -15,7 +15,9 @@
1515
"css-loader": "0.1.x",
1616
"less-loader": "0.1.x",
1717
"style-loader": "0.1.x",
18-
"script-loader": "0.1.x"
18+
"script-loader": "0.1.x",
19+
"bundle-loader": "0.1.x",
20+
"val-loader": "0.1.x"
1921
},
2022
"licenses": [
2123
{

require-polyfill.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ var options = module.exports.options = {
144144
{test: /\.coffee$/, loader: "coffee"},
145145
// {test: /\.json$/, loader: "json"}, // This works out of the box in node.js
146146
{test: /\.jade$/, loader: "jade"},
147-
{test: /\.css$/, loader: "style!css"}
147+
{test: /\.css$/, loader: "style!css"},
148+
{test: /\.less$/, loader: "style!css!val!less"}
148149
],
149150
loaderExtensions: [".webpack-loader.js", ".loader.js", ".js", ""],
150151
loaderPostfixes: ["-webpack-loader", "-loader", ""]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var fs = require("fs");
2+
var path = require("path");
3+
module.exports = fs.readFileSync(path.join(path.dirname(__filename), "stylesheet.css"), "utf-8") + "\n/* generated */";

test/browsertest/lib/index.web.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ window.test(require("../resources/script.coffee") === "coffee test", "Buildin 'c
125125
window.test(require("css!../css/stylesheet.css").indexOf(".rule-direct") !== -1, "Buildin 'css' loader, direct content");
126126
window.test(require("css!../css/stylesheet.css").indexOf(".rule-import1") !== -1, "Buildin 'css' loader, imported rule");
127127
window.test(require("css!../css/stylesheet.css").indexOf(".rule-import2") !== -1, "Buildin 'css' loader, double imported rule");
128+
window.test(require("css!val!../css/generateCss").indexOf("generated") !== -1, "Buildin 'val' loader, combined with css");
129+
window.test(require("css!val!../css/generateCss").indexOf(".rule-import2") !== -1, "Buildin 'val' loader, combined with css, imported css");
130+
window.test(require("raw!val!../css/generateCss").indexOf("generated") !== -1, "Buildin 'val' loader, combined with raw");
128131
window.test(require("less!../less/stylesheet.less").indexOf(".less-rule-direct") !== -1, "Buildin 'less' loader, direct content");
129132
window.test(require("less!../less/stylesheet.less").indexOf(".less-rule-import1") !== -1, "Buildin 'less' loader, imported rule");
130133
window.test(require("less!../less/stylesheet.less").indexOf(".less-rule-import2") !== -1, "Buildin 'less' loader, double imported rule");
@@ -138,7 +141,5 @@ window.test(require("../resources/" + scr) === "coffee test", "context should pr
138141
window.test(require("raw!../resources/" + abc + ".txt") === "abc", "raw loader with context");
139142

140143

141-
require.ensure([], function(require) {
142-
// Tests from node.js
143-
require("../nodetests");
144-
});
144+
// Tests from node.js
145+
require("bundle!../nodetests");

0 commit comments

Comments
 (0)