Skip to content

Commit dca4803

Browse files
author
chuckd
committed
Add buildEnvironment plugin option
1 parent e38ec61 commit dca4803

20 files changed

+148
-25
lines changed

README.md

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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
}
Lines changed: 8 additions & 0 deletions
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+
});
Lines changed: 9 additions & 0 deletions
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+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define([], function() {
2+
return "foo";
3+
});
Lines changed: 13 additions & 0 deletions
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+
};
Lines changed: 8 additions & 0 deletions
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+
});
Lines changed: 6 additions & 0 deletions
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+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define([], function() {
2+
return "foo";
3+
});
Lines changed: 12 additions & 0 deletions
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+
};
Lines changed: 8 additions & 0 deletions
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+
});
Lines changed: 9 additions & 0 deletions
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+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define([], function() {
2+
return "foo";
3+
});
Lines changed: 12 additions & 0 deletions
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+
};
Lines changed: 5 additions & 0 deletions
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+
});
Lines changed: 9 additions & 0 deletions
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+
};
Lines changed: 11 additions & 0 deletions
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+
};

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function runTestCases(casesPath, isErrorTest) {
5252
describe(category.name, function() {
5353
category.tests.forEach(function(testName) {
5454
var suite = describe(testName, function() {});
55-
it(testName + isErrorTest ? " should fail" : " should compile", function(done) {
55+
it(testName + (isErrorTest ? " should fail" : " should compile"), function(done) {
5656
this.timeout(60000);
5757
var testDirectory = path.join(casesPath, category.name, testName);
5858
var outputDirectory = path.join(__dirname, "js", "TestCases", category.name, testName);

0 commit comments

Comments
 (0)