You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #525 Allow setOutputPath to create nested directories (Lyrkan)
This PR was merged into the master branch.
Discussion
----------
Allow setOutputPath to create nested directories
This PR changes the check that is currently made when calling `setOutputPath` in order to allow the creation of nested directories (closes#189).
Note that it doesn't remove it entirely since it still prevents the creation of more than one level when the output path is located outside of the context path.
For instance, given the context is `/home/foo/bar/`:
```js
// Will work
Encore.setOutputPath('build');
// Will work, even if "/home/foo/bar/public" does not exist
Encore.setOutputPath('public/build/output');
// Will work, even if "/home/foo/public" does not exist
Encore.setOutputPath('../public');
// Will work if only "/home/foo/public/build" does not exist
// ... but **won't** work if "/home/foo/public" does not exist
Encore.setOutputPath('../public/build');
```
Commits
-------
ff200af Allow setOutputPath to create nested directories
Copy file name to clipboardExpand all lines: lib/WebpackConfig.js
+17-5Lines changed: 17 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -130,11 +130,23 @@ class WebpackConfig {
130
130
}
131
131
132
132
if(!fs.existsSync(outputPath)){
133
-
// for safety, we won't recursively create directories
134
-
// this might be a sign that the user has specified
135
-
// an incorrect path
136
-
if(!fs.existsSync(path.dirname(outputPath))){
137
-
thrownewError(`outputPath directory does not exist: ${outputPath}. Please check the path you're passing to setOutputPath() or create this directory`);
133
+
// If the parent of the output directory does not exist either
134
+
// check if it is located under the context directory before
135
+
// creating it and its parent.
136
+
constparentPath=path.dirname(outputPath);
137
+
if(!fs.existsSync(parentPath)){
138
+
constcontext=path.resolve(this.getContext());
139
+
if(outputPath.indexOf(context)!==0){
140
+
thrownewError(`outputPath directory "${outputPath}" does not exist and is not located under the context directory "${context}". Please check the path you're passing to setOutputPath() or create this directory.`);
0 commit comments