Skip to content

Commit

Permalink
Further improvements to how paths for output files are generated in u…
Browse files Browse the repository at this point in the history
…nbundled mode
  • Loading branch information
patrick-steele-idem committed Jan 12, 2016
1 parent 7c34bf6 commit f54c2a3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/BundleMappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,33 @@ BundleMappings.prototype = {
bundle.dependency = dependency;
bundle.isExternalResource = true;
} else if (this.bundlingEnabled === false) {
// Bundling is NOT enabled

// We will try to find a relative path that will be used for
// the output file of the bundle.
// This relative path might be different from the bundle name
// if a defaultBundleName is provided
//
// NOTE: If we don't have a defaultBundleName for this dependency
// and if we don't find a relative path then we will use
// `${dependencyType}-${pageBundleName}` as the
// bundle name.

var sourceFile;
var relPath;

var unbundledTargetPrefix;

if (dependency.getUnbundledTargetPrefix) {
// The unbundled target prefix adds a common prefix to the beginning of
// relative paths for all output files
unbundledTargetPrefix = dependency.getUnbundledTargetPrefix(lassoContext);
}

if (dependency.getUnbundledTarget) {
// The dependency provides a getUnbundledTarget(lassoContext)
// so we will try to use that determine a relative path
// which will be used as the bundle name
sourceFile = dependency.getUnbundledTarget(lassoContext) + '-' + pageBundleName.replace(/[\\\/]/g, '-');
}

Expand All @@ -200,8 +223,16 @@ BundleMappings.prototype = {
var projectRoot = this.config.getProjectRoot();

if (sourceFile.startsWith(projectRoot + fileSep)) {
// source file is within the project root directory
// so let's remove the project root directory
// path from the source file path which will
// leave us with a relative path
relPath = sourceFile.substring(projectRoot.length);
} else {
// source file seems to be outside the project root
// directory so we will see if we can resolve
// the module associated with the source file and
// use that build an appropriate relative path
var dirname = nodePath.dirname(sourceFile);
if (dirname) {
var modulePkg = tryGetModuleRootPackage(dirname);
Expand All @@ -221,6 +252,12 @@ BundleMappings.prototype = {
relPath = sourceFile;
}

if (unbundledTargetPrefix) {
// If an unbundledTargetPrefix is provided then add that
// to the start of the relative path.
relPath = nodePath.join(unbundledTargetPrefix, relPath);
}

bundle = this.addDependencyToBundle(
dependency,
dependency.defaultBundleName || relPath || (dependency.type + '-' + pageBundleName),
Expand All @@ -230,9 +267,12 @@ BundleMappings.prototype = {

// bundle.dependency = dependency;
if (relPath) {
// We associate this bundle with a relative path which will
// be used as the output file for the bundle
bundle.relativeOutputPath = relPath;
}
} else {
// Bundling is enabled
//Make sure the dependency is part of a bundle. If it not part of a preconfigured bundle then put it in a page-specific bundle
bundle = this.addDependencyToBundle(
dependency,
Expand Down

0 comments on commit f54c2a3

Please sign in to comment.