Skip to content

Commit 55ba0e9

Browse files
author
Chuck Dumont
authored
Merge pull request #58 from chuckdumont/work2
Add support for dojo/query selector engines specified using loader plugin syntax
2 parents e11b675 + 195f22f commit 55ba0e9

File tree

6 files changed

+44
-5
lines changed

6 files changed

+44
-5
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ new webpack.NormalModuleReplacementPlugin(/^dojo\/selector\/_loader!/, "dojo/sel
104104
new webpack.NormalModuleReplacementPlugin(/^dojo\/request\/default!/, "dojo/request/xhr"),
105105
new webpack.NormalModuleReplacementPlugin(/^dojo\/text!/, function(data) {
106106
data.request = data.request.replace(/^dojo\/text!/, "!!raw!");
107+
}),
108+
new NormalModuleReplacementPlugin(/^dojo\/query!/, data => {
109+
var match = /^dojo\/query!(.*)$/.exec(data.request);
110+
data.request = "dojo/loaderProxy?loader=dojo/query&name=" + match[1] + "!";
107111
})
108112
```
109113

@@ -157,10 +161,12 @@ new webpack.NormalModuleReplacementPlugin(
157161
)
158162
```
159163

160-
The general syntax for the `dojo/loaderProxy` loader extension is `dojo/loaderProxy?loader=<loader>&deps=<dependencies>!<resource>` where *loader* specifies the Dojo loader extension to run on the client and *dependencies* specifies a comma separated list of module dependencies to add to the packed resources. In the example above, if the client code specifies the module as `svg!closeBtn.svg`, then the translated module will be `dojo/loaderProxy?loader=svg&deps=dojo/text%21closeBtn.svg!closeBtn.svg`. Note the need to URL encode the `!` character so as not to trip up parsing.
164+
The general syntax for the `dojo/loaderProxy` loader extension is `dojo/loaderProxy?loader=<loader>&deps=<dependencies>&name=<resource>!<resource>` where *loader* specifies the Dojo loader extension to run on the client and *dependencies* specifies a comma separated list of module dependencies to add to the packed resources. In the example above, if the client code specifies the module as `svg!closeBtn.svg`, then the translated module will be `dojo/loaderProxy?loader=svg&deps=dojo/text%21closeBtn.svg!closeBtn.svg`. Note the need to URL encode the `!` character so as not to trip up parsing.
161165

162166
Specifying `dojo/text!closeBtn.svg` as a dependency ensures that when it is required by the `svg` loader extension's load method on the client, then the dependency will be resolved in-line and the `load` method's callback will be invoked in-line as required.
163167

168+
The *name* query arg is optional and is provided for cases where the resource name (the text to the right of the "!") does not represent a module. Since webpack requires the resource name to represent a valid module, you can use the *name* query arg to specify non-module resources. For example, the loaderProxy URL for `dojo/query!css2` would be `dojo/loaderProxy?loader=dojo/query&name=css2!`.
169+
164170
# Options
165171

166172
The plugin is instantiated with a properties map specifying the following options:

lib/DojoAMDPlugin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,20 @@ Refer to https://github.com/OpenNTF/dojo-webpack-plugin/blob/master/README.md#bu
133133

134134
compiler.plugin("normal-module-factory", () => {
135135
compiler.apply(
136-
new NormalModuleReplacementPlugin(/^dojo\/selector\/_loader!/, (data) => {
136+
new NormalModuleReplacementPlugin(/^dojo\/selector\/_loader!/, data => {
137137
data.absMidAliases.push(data.absMid);
138138
data.absMid = data.request = "dojo/selector/lite";
139139
}),
140-
new NormalModuleReplacementPlugin(/^dojo\/request\/default!/, (data) => {
140+
new NormalModuleReplacementPlugin(/^dojo\/request\/default!/, data => {
141141
data.absMidAliases.push(data.absMid);
142142
data.absMid = data.request = "dojo/request/xhr";
143143
}),
144-
new NormalModuleReplacementPlugin(/^dojo\/text!/, (data) => {
144+
new NormalModuleReplacementPlugin(/^dojo\/text!/, data => {
145145
data.request = data.request.replace(/^dojo\/text!/, "!!raw-loader!");
146+
}),
147+
new NormalModuleReplacementPlugin(/^dojo\/query!/, data => {
148+
var match = /^dojo\/query!(.*)$/.exec(data.request);
149+
data.request = "dojo/loaderProxy?loader=dojo/query&name=" + match[1] + "!";
146150
})
147151
);
148152
});

loaders/dojo/loaderProxy/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function() {
2323
if (!loader) {
2424
throw new Error("No loader specified");
2525
}
26-
const name = this._module.absMid.split("!").pop();
26+
const name = query.name || this._module.absMid.split("!").pop();
2727
const deps = query.deps ? query.deps.split(",") : [];
2828
var issuerAbsMid, issuer = this._module.issuer;
2929
if (issuer) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
define(["dojo/query!css2"], function(engine) {
2+
it("should load text files" , function() {
3+
"css2".should.be.eql(engine);
4+
});
5+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
define([], function() {
2+
return {
3+
load: function(name, req__, callback) {
4+
callback(name);
5+
}
6+
};
7+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
module.exports = {
4+
entry: "test/index",
5+
plugins: [
6+
new DojoWebpackPlugin({
7+
loaderConfig: {
8+
paths:{test: "."}
9+
},
10+
loader: path.join(__dirname, "../../../js/dojo/dojo.js")
11+
})
12+
],
13+
resolve: {
14+
alias: {
15+
'dojo/query': path.join(__dirname, "./query.js")
16+
}
17+
}};

0 commit comments

Comments
 (0)