Skip to content

Commit 08ab683

Browse files
author
Chuck Dumont
authored
Merge pull request #66 from chuckdumont/work2
Add buildEnvironment plugin option
2 parents 738cc1e + 20073d8 commit 08ab683

19 files changed

+147
-24
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ This property is required and specifies the Dojo loader config. See [The Dojo l
179179

180180
Used only if the `loaderConfig` is a string specifying the name of a module and that module exports a function which returns the config. The environment is passed to the function when it is called to get the config. This should be a JSON type object because it gets stringified for export to the client.
181181

182+
### buildEnvironment
183+
184+
Simialr to `environment`, but used exclusively at build time. If both are specified, then `buildEnvironment` will be passed to the `loaderConfig` function when building, and `environment` will be passed to the `loaderConfig` function when the built application is loaded in the browser. This facilitates specifying different `loaderConfig` paths (e.g. `baseUrl`) for build vs. run. If only `environment` is specified, then it is used for both.
185+
182186
### loader
183187

184188
This property is optional and specifies the module path of the built Dojo loader. See [Building the Dojo loader](#building-the-dojo-loader) for details. If not specified, then the loader will be built as part of the Webpack build.

lib/DojoAMDPlugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = class DojoAMDPlugin {
6464
if (util.isString(this.options.loaderConfig)) {
6565
loaderConfig = require(this.options.loaderConfig);
6666
if (typeof loaderConfig === 'function') {
67-
loaderConfig = loaderConfig(this.options.environment || {});
67+
loaderConfig = loaderConfig(this.options.buildEnvironment || this.options.environment || {});
6868
}
6969
} else {
7070
loaderConfig = this.options.loaderConfig;

package-lock.json

+22-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@
3838
"mocha": "^3.5.3",
3939
"mocha-lcov-reporter": "^1.3.0",
4040
"should": "^13.1.0",
41-
"webpack": ">= 2.2.0"
41+
"webpack": "3.7.1"
4242
}
4343
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define(["foo"], function(foo) {
2+
it ("should load foo", function() {
3+
foo.should.be.eql("foo");
4+
});
5+
it ("Should resolve foo as defined by environment", function() {
6+
require.rawConfig.paths.foo.should.be.eql("/foo");
7+
});
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("should");
2+
module.exports = function(env) {
3+
it("foopath should be defined in environment", function() {
4+
env.foopath.should.be.defined;
5+
});
6+
return {
7+
paths: {foo: env.foopath}
8+
};
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define([], function() {
2+
return "foo";
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
module.exports = {
4+
entry: "./index",
5+
plugins: [
6+
new DojoWebpackPlugin({
7+
loaderConfig: require.resolve("./loaderConfig"),
8+
environment: {foopath: "/foo"},
9+
buildEnvironment: {foopath: "test/foo"},
10+
loader: path.join(__dirname, "../../../js/dojo/dojo.js")
11+
})
12+
]
13+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define(["foo"], function(foo) {
2+
it ("should load foo", function() {
3+
foo.should.be.eql("foo");
4+
});
5+
it ("Should not resolve foo as defined by environment", function() {
6+
(typeof require.rawConfig.paths.foo === 'undefined').should.be.true;
7+
});
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require("should");
2+
module.exports = function(env) {
3+
return {
4+
paths: {foo: env.foopath}
5+
};
6+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define([], function() {
2+
return "foo";
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
module.exports = {
4+
entry: "./index",
5+
plugins: [
6+
new DojoWebpackPlugin({
7+
loaderConfig: require.resolve("./loaderConfig"),
8+
buildEnvironment: {foopath: "test/foo"},
9+
loader: path.join(__dirname, "../../../js/dojo/dojo.js")
10+
})
11+
]
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
define(["foo"], function(foo) {
2+
it ("should load foo", function() {
3+
foo.should.be.eql("foo");
4+
});
5+
it ("Should resolve foo as defined by environment", function() {
6+
require.rawConfig.paths.foo.should.be.eql("test/foo");
7+
});
8+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("should");
2+
module.exports = function(env) {
3+
it("env should specify fooptah", function() {
4+
env.foopath.should.be.eql("test/foo");
5+
});
6+
return {
7+
paths: {foo: env.foopath}
8+
};
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define([], function() {
2+
return "foo";
3+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
module.exports = {
4+
entry: "./index",
5+
plugins: [
6+
new DojoWebpackPlugin({
7+
loaderConfig: require.resolve("./loaderConfig"),
8+
environment: {foopath: "test/foo"},
9+
loader: path.join(__dirname, "../../../js/dojo/dojo.js")
10+
})
11+
]
12+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
define([], function() {
2+
it ("Should resolve path as defined in loader config", function() {
3+
require.toUrl('foo/bar').should.be.eql("/test/foo/bar");
4+
});
5+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("should");
2+
module.exports = function(env) {
3+
it("should have empty env", function() {
4+
Object.keys(env).length.should.be.eql(0);
5+
});
6+
return {
7+
paths: {foo: "/test/foo"}
8+
};
9+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var path = require("path");
2+
var DojoWebpackPlugin = require("../../../../index");
3+
module.exports = {
4+
entry: "./index",
5+
plugins: [
6+
new DojoWebpackPlugin({
7+
loaderConfig: require.resolve("./loaderConfig"),
8+
loader: path.join(__dirname, "../../../js/dojo/dojo.js")
9+
})
10+
]
11+
};

0 commit comments

Comments
 (0)