File tree 3 files changed +17
-3
lines changed
3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 72
72
"type" : " string" ,
73
73
"default" : " " ,
74
74
"description" : " The output path (relative to the outDir)."
75
+ },
76
+ "allowOutsideOutDir" : {
77
+ "type" : " boolean" ,
78
+ "description" : " Allow assets to be copied outside the outDir." ,
79
+ "default" : false
75
80
}
76
81
},
77
82
"additionalProperties" : false
Original file line number Diff line number Diff line change @@ -95,12 +95,20 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
95
95
asset . output = asset . output || '' ;
96
96
asset . glob = asset . glob || '' ;
97
97
98
- // Prevent asset configurations from writing outside of the output path
98
+ // Prevent asset configurations from writing outside of the output path, except if the user
99
+ // specify a configuration flag.
100
+ // Also prevent writing outside the project path. That is not overridable.
99
101
const fullOutputPath = path . resolve ( buildOptions . outputPath , asset . output ) ;
100
- if ( ! fullOutputPath . startsWith ( path . resolve ( buildOptions . outputPath ) ) ) {
101
- const message = 'An asset cannot be written to a location outside of the output path .' ;
102
+ if ( ! fullOutputPath . startsWith ( projectRoot ) ) {
103
+ const message = 'An asset cannot be written to a location outside the project .' ;
102
104
throw new SilentError ( message ) ;
103
105
}
106
+ if ( ! fullOutputPath . startsWith ( path . resolve ( buildOptions . outputPath ) ) ) {
107
+ if ( ! asset . allowOutsideOutDir ) {
108
+ const message = 'An asset cannot be written to a location outside of the output path.' ;
109
+ throw new SilentError ( message ) ;
110
+ }
111
+ }
104
112
105
113
// Ensure trailing slash.
106
114
if ( isDirectory ( path . resolve ( asset . input ) ) ) {
Original file line number Diff line number Diff line change @@ -92,4 +92,5 @@ export interface AssetPattern {
92
92
glob : string ;
93
93
input ?: string ;
94
94
output ?: string ;
95
+ allowOutsideOutDir ?: boolean ;
95
96
}
You can’t perform that action at this time.
0 commit comments