Skip to content

Commit

Permalink
Merge pull request #7 from VladimirMikulic/feature/multiple-entries-s…
Browse files Browse the repository at this point in the history
…upport

ADD: Support for multiple entries
  • Loading branch information
VladimirMikulic committed Mar 29, 2020
2 parents a85d81c + 6283f58 commit 8954456
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"prefer-const": "warn",
"arrow-parens": "off",
"prefer-destructuring": "off",
"no-param-reassign": "warn"
"no-param-reassign": "warn",
"no-restricted-syntax": "off"
},
"ignorePatterns": ["dist*", "test"]
}
37 changes: 29 additions & 8 deletions lib/DependencyGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ class DependencyGraph extends DepGraph {
}

buildDependencyGraph() {
const entryAssetPath = this.entryAssetPath;
const entryAssets = this.entryAssets;

this.addNode(entryAssetPath);
this.buildDependencyAssets(this.bundle.entryAsset, entryAssetPath);
for (const entryAsset of entryAssets) {
const entryAssetPath = entryAsset.parentBundle.name;

this.bundle.childBundles.forEach(asset => {
this.buildAssetDependecies(asset);
});
this.addNode(entryAssetPath);
this.buildDependencyAssets(entryAsset, entryAssetPath);

this.bundle.childBundles.forEach(asset => {
this.buildAssetDependecies(asset);
});
}
}

buildAssetDependecies(asset) {
Expand Down Expand Up @@ -70,8 +74,25 @@ class DependencyGraph extends DepGraph {
}, []);
}

get entryAssetPath() {
return this.bundle.entryAsset.parentBundle.name;
get entryAssets() {
const assets = [];

// If there is only one entry asset
if (this.bundle.entryAsset) {
assets.push(this.bundle.entryAsset);
} else {
// If we have multiple entry assets
const bundles = Array.from(this.bundle.childBundles);
bundles.forEach(bundle => {
assets.push(bundle.entryAsset);
});
}

return assets;
}

get entryAssetPaths() {
return this.entryAssets.map(asset => asset.parentBundle.name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/FileProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class FileProcessor {
// Don't update the path in the entry file because it already contains a valid link
if (
process.env.firstRun === 'false' &&
fileDependantPath === this.depGraph.entryAssetPath
this.depGraph.entryAssetPaths.includes(fileDependantPath)
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parcel-plugin-custom-dist-structure",
"version": "1.1.1",
"version": "1.1.2",
"description": "Parcel plugin that allows you to specify a custom dist structure.",
"main": "lib/index.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions test/example-src/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/style2.css">
</head>

<body>

<img src="img/this.jpg" alt="">
<script src="./js/script.js"></script>
<script src="js/script.js"></script>
</body>

</html>
</html>

0 comments on commit 8954456

Please sign in to comment.