File tree Expand file tree Collapse file tree
test/configCases/css/contenthash Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -368,24 +368,24 @@ class CssModulesPlugin {
368368
369369 /** @type {CssModule[] | undefined } */
370370 const modules = orderedCssModulesPerChunk . get ( chunk ) ;
371- const { path : filename , info } = compilation . getPathWithInfo (
372- CssModulesPlugin . getChunkFilenameTemplate (
373- chunk ,
374- compilation . outputOptions
375- ) ,
376- {
377- hash,
378- runtime : chunk . runtime ,
379- chunk,
380- contentHashType : "css"
381- }
382- ) ;
383- const undoPath = getUndoPath (
384- filename ,
385- compilation . outputOptions . path ,
386- false
387- ) ;
388371 if ( modules !== undefined ) {
372+ const { path : filename , info } = compilation . getPathWithInfo (
373+ CssModulesPlugin . getChunkFilenameTemplate (
374+ chunk ,
375+ compilation . outputOptions
376+ ) ,
377+ {
378+ hash,
379+ runtime : chunk . runtime ,
380+ chunk,
381+ contentHashType : "css"
382+ }
383+ ) ;
384+ const undoPath = getUndoPath (
385+ filename ,
386+ compilation . outputOptions . path ,
387+ false
388+ ) ;
389389 result . push ( {
390390 render : ( ) =>
391391 this . renderChunk ( {
Original file line number Diff line number Diff line change 1+ body {
2+ background : yellow;
3+ color : green;
4+ }
Original file line number Diff line number Diff line change 1+ export const name = 'async' ;
Original file line number Diff line number Diff line change 1+ import * as style from "./style.css" ;
2+
3+ it ( "should work with js" , done => {
4+ import ( './async.js' ) . then ( x => {
5+ expect ( x . name ) . toBe ( "async" )
6+ done ( ) ;
7+ } , done ) ;
8+ } ) ;
9+
10+ it ( "should work with css" , done => {
11+ expect ( style ) . toEqual ( nsObj ( { } ) ) ;
12+
13+ const computedStyle = getComputedStyle ( document . body ) ;
14+
15+ expect ( computedStyle . getPropertyValue ( "background" ) ) . toBe ( " green" ) ;
16+ expect ( computedStyle . getPropertyValue ( "color" ) ) . toBe ( " yellow" ) ;
17+
18+ import ( "./async.css" ) . then ( x => {
19+ expect ( x ) . toEqual ( nsObj ( { } ) ) ;
20+
21+ const style = getComputedStyle ( document . body ) ;
22+
23+ expect ( style . getPropertyValue ( "background" ) ) . toBe ( " yellow" ) ;
24+ expect ( style . getPropertyValue ( "color" ) ) . toBe ( " green" ) ;
25+
26+ done ( ) ;
27+ } , done ) ;
28+ } ) ;
Original file line number Diff line number Diff line change 1+ body {
2+ background : green;
3+ color : yellow;
4+ }
Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+
3+ let cssBundle ;
4+
5+ module . exports = {
6+ findBundle : function ( _ , options ) {
7+ const jsBundleRegex = new RegExp ( / ^ b u n d l e \. .+ \. j s $ / , "i" ) ;
8+ const cssBundleRegex = new RegExp ( / ^ b u n d l e \. .+ \. c s s $ / , "i" ) ;
9+ const asyncRegex = new RegExp ( / ^ a s y n c \. .+ \. j s $ / , "i" ) ;
10+ const files = fs . readdirSync ( options . output . path ) ;
11+ const jsBundle = files . find ( file => jsBundleRegex . test ( file ) ) ;
12+
13+ if ( ! jsBundle ) {
14+ throw new Error (
15+ `No file found with correct name (regex: ${
16+ jsBundleRegex . source
17+ } , files: ${ files . join ( ", " ) } )`
18+ ) ;
19+ }
20+
21+ const async = files . find ( file => asyncRegex . test ( file ) ) ;
22+
23+ if ( ! async ) {
24+ throw new Error (
25+ `No file found with correct name (regex: ${
26+ asyncRegex . source
27+ } , files: ${ files . join ( ", " ) } )`
28+ ) ;
29+ }
30+
31+ cssBundle = files . find ( file => cssBundleRegex . test ( file ) ) ;
32+
33+ if ( ! cssBundle ) {
34+ throw new Error (
35+ `No file found with correct name (regex: ${
36+ cssBundleRegex . source
37+ } , files: ${ files . join ( ", " ) } )`
38+ ) ;
39+ }
40+
41+ return [ jsBundle , async ] ;
42+ } ,
43+ moduleScope ( scope ) {
44+ const link = scope . window . document . createElement ( "link" ) ;
45+ link . rel = "stylesheet" ;
46+ link . href = cssBundle ;
47+ scope . window . document . head . appendChild ( link ) ;
48+ }
49+ } ;
Original file line number Diff line number Diff line change 1+ /** @type {import("../../../../").Configuration } */
2+ module . exports = {
3+ target : "web" ,
4+ mode : "development" ,
5+ output : {
6+ filename : "bundle.[name].[contenthash].js" ,
7+ cssFilename : "bundle.[name].[contenthash].css" ,
8+ chunkFilename : "async.[name].[contenthash].js" ,
9+ cssChunkFilename : "async.[name].[contenthash].css"
10+ } ,
11+ experiments : {
12+ css : true
13+ }
14+ } ;
You can’t perform that action at this time.
0 commit comments