File tree 4 files changed +39
-8
lines changed
packages/angular_devkit/build_angular/src/webpack
4 files changed +39
-8
lines changed Original file line number Diff line number Diff line change @@ -249,7 +249,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
249
249
return prev ;
250
250
} , [ ] ) ;
251
251
252
- // Add a new asset for each entry.
252
+ // Add a new asset for each entry.
253
253
for ( const script of globalScriptsByBundleName ) {
254
254
// Lazy scripts don't get a hash, otherwise they can't be loaded by name.
255
255
const hash = script . inject ? hashFormat . script : '' ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
17
17
RemoveHashPlugin ,
18
18
SuppressExtractedTextChunksWebpackPlugin ,
19
19
} from '../plugins' ;
20
- import { getOutputHashFormat , normalizeExtraEntryPoints } from '../utils/helpers' ;
20
+ import { assetNameTemplateFactory , getOutputHashFormat , normalizeExtraEntryPoints } from '../utils/helpers' ;
21
21
22
22
// tslint:disable-next-line:no-big-function
23
23
export function getStylesConfig ( wco : WebpackConfigOptions ) {
@@ -154,6 +154,8 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
154
154
} ,
155
155
] ;
156
156
157
+ const assetNameTemplate = assetNameTemplateFactory ( hashFormat ) ;
158
+
157
159
const postcssOptionsCreator = ( sourceMap : boolean , extracted : boolean | undefined ) => {
158
160
return ( loader : webpack . loader . LoaderContext ) => ( {
159
161
map : sourceMap && {
@@ -183,7 +185,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
183
185
deployUrl : buildOptions . deployUrl ,
184
186
resourcesOutputPath : buildOptions . resourcesOutputPath ,
185
187
loader,
186
- filename : `[name] ${ hashFormat . file } .[ext]` ,
188
+ filename : assetNameTemplate ,
187
189
emitFile : buildOptions . platform !== 'server' ,
188
190
extracted,
189
191
} ) ,
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ export interface PostcssCliResourcesOptions {
31
31
rebaseRootRelative ?: boolean ;
32
32
/** CSS is extracted to a `.css` or is embedded in a `.js` file. */
33
33
extracted ?: boolean ;
34
- filename : string ;
34
+ filename : ( resourcePath : string ) => string ;
35
35
loader : webpack . loader . LoaderContext ;
36
36
emitFile : boolean ;
37
37
}
@@ -113,10 +113,11 @@ export default function(options?: PostcssCliResourcesOptions): Plugin {
113
113
}
114
114
115
115
let outputPath = interpolateName (
116
- { resourcePath : result } as webpack . loader . LoaderContext ,
117
- filename ,
118
- { content } ,
119
- ) ;
116
+ { resourcePath : result } as webpack . loader . LoaderContext ,
117
+ filename ( result ) ,
118
+ { content, context : loader . context || loader . rootContext } ,
119
+ )
120
+ . replace ( / \\ | \/ / g, '-' ) ;
120
121
121
122
if ( resourcesOutputPath ) {
122
123
outputPath = path . posix . join ( resourcesOutputPath , outputPath ) ;
Original file line number Diff line number Diff line change 7
7
*/
8
8
9
9
import { basename , normalize } from '@angular-devkit/core' ;
10
+ import * as path from 'path' ;
10
11
import { ScriptTarget } from 'typescript' ;
11
12
import { Options , SourceMapDevToolPlugin } from 'webpack' ;
12
13
import { ExtraEntryPoint , ExtraEntryPointClass } from '../../browser/schema' ;
@@ -124,3 +125,30 @@ export function getWatchOptions(poll: number | undefined): Options.WatchOptions
124
125
ignored : poll === undefined ? undefined : withWebpackFourOrFive ( / [ \\ \/ ] n o d e _ m o d u l e s [ \\ \/ ] / , 'node_modules/**' ) ,
125
126
} ;
126
127
}
128
+
129
+ export function assetNameTemplateFactory ( hashFormat : HashFormat ) : ( resourcePath : string ) => string {
130
+ const visitedFiles = new Map < string , string > ( ) ;
131
+
132
+ return ( resourcePath : string ) => {
133
+ if ( hashFormat . file ) {
134
+ // File names are hashed therefore we don't need to handle files with the same file name.
135
+ return `[name]${ hashFormat . file } .[ext]` ;
136
+ }
137
+
138
+ const filename = path . basename ( resourcePath ) ;
139
+ // Check if the file with the same name has already been processed.
140
+ const visited = visitedFiles . get ( filename ) ;
141
+ if ( ! visited ) {
142
+ // Not visited.
143
+ visitedFiles . set ( filename , resourcePath ) ;
144
+
145
+ return filename ;
146
+ } else if ( visited === resourcePath ) {
147
+ // Same file.
148
+ return filename ;
149
+ }
150
+
151
+ // File has the same name but it's in a different location.
152
+ return '[path][name].[ext]' ;
153
+ } ;
154
+ }
You can’t perform that action at this time.
0 commit comments