Skip to content

Commit e4c2857

Browse files
committed
First working test of mainConfigFile, and code changes to match.
1 parent 88d149b commit e4c2857

File tree

9 files changed

+74
-2
lines changed

9 files changed

+74
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ build/tests/lib/namespace/foo.js
88
build/tests/lib/plugins/main-built.js
99
build/tests/lib/plugins/main-builtPluginFirst.js
1010
build/tests/lib/dotpackage/built
11+
build/tests/lib/mainConfigFile/basic/main-built.js
1112
build/tests/lib/moduleThenPlugin/built.js
1213
build/tests/lib/nameInsertion/built.js
1314
build/tests/lib/nested/main-built.js

build/example.build.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
//baseUrl should be specified as relative to the appDir.
2525
baseUrl: "./",
2626

27+
//By default all the configuration for optimization happens from the command
28+
//line or by properties in the a config file, and configuration that was
29+
//passed to requirejs as part of the app's runtime "main" JS file is *not*
30+
//considered. However, if you prefer for the that "main" JS file configuration
31+
//to be read for the build so that you do not have to duplicate the values
32+
//in a separate configuration, set this property to the location of that
33+
//main JS file. The first requirejs({}), require({}), requirejs.config({}),
34+
//or require.config({}) call found in that file will be used.
35+
mainConfigFile: '../some/path/to/main.js',
36+
2737
//Set paths for modules. If relative paths, set relative to baseUrl above.
2838
//If a special value of "empty:" is used for the path value, then that
2939
//acts like mapping the path to an empty file. It allows the optimizer to

build/jslib/build.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,13 @@ function (lang, logger, file, parse, optimize, pragma,
625625

626626
mainConfigFile = config.mainConfigFile || buildFileConfig.mainConfigFile;
627627
if (mainConfigFile) {
628+
mainConfigFile = build.makeAbsPath(mainConfigFile, absFilePath);
628629
mainConfig = parse.findConfig(mainConfigFile, file.readFile(mainConfigFile));
629630
if (mainConfig) {
630-
//Need to mix in config from configMain first, and
631-
//all paths are relative to mainConfig.
631+
//If no baseUrl, then use the directory holding the main config.
632+
if (!mainConfig.baseUrl) {
633+
mainConfig.baseUrl = mainConfigFile.substring(0, mainConfigFile.lastIndexOf('/'));
634+
}
632635
build.makeAbsConfig(mainConfig, mainConfigFile);
633636
lang.mixin(config, mainConfig, true);
634637
}

build/tests/builds.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,4 +537,21 @@ define(['build', 'env!env/file'], function (build, file) {
537537
);
538538
doh.run();
539539

540+
doh.register("mainConfigFileBasic",
541+
[
542+
function mainConfigFileBasic(t) {
543+
file.deleteFile("lib/mainConfigFile/basic/main-built.js");
544+
545+
build(["lib/mainConfigFile/basic/tools/build.js"]);
546+
547+
t.is(nol(c("lib/mainConfigFile/basic/expected.js")),
548+
nol(c("lib/mainConfigFile/basic/main-built.js")));
549+
550+
require._buildReset();
551+
}
552+
553+
]
554+
);
555+
doh.run();
556+
540557
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
define('dep1',{
3+
name: 'dep1'
4+
});
5+
6+
define('dep2',{
7+
name: 'dep2'
8+
});
9+
10+
requirejs.config({
11+
paths: {
12+
'dep2': 'sub/dep2'
13+
}
14+
});
15+
16+
requirejs(['dep1', 'dep2'], function () {
17+
18+
});
19+
20+
define("main", function(){});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
({
2+
mainConfigFile: '../www/js/main.js',
3+
name: 'main',
4+
out: '../main-built.js',
5+
optimize: 'none'
6+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
name: 'dep1'
3+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
requirejs.config({
2+
paths: {
3+
'dep2': 'sub/dep2'
4+
}
5+
});
6+
7+
requirejs(['dep1', 'dep2'], function () {
8+
9+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
define({
2+
name: 'dep2'
3+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy