@@ -485,6 +485,51 @@ describe('HtmlWebpackPlugin', () => {
485
485
} , [ '<link href="styles.css?%hash%"' ] , null , done ) ;
486
486
} ) ;
487
487
488
+ it ( 'should allow to add cache hashes to with the css assets' , done => {
489
+ testHtmlPlugin ( {
490
+ mode : 'production' ,
491
+ entry : path . join ( __dirname , 'fixtures/theme.js' ) ,
492
+ output : {
493
+ path : OUTPUT_DIR ,
494
+ filename : 'index_bundle.js' ,
495
+ publicPath : 'some/'
496
+ } ,
497
+ module : {
498
+ rules : [
499
+ { test : / \. c s s $ / , use : [ MiniCssExtractPlugin . loader , 'css-loader' ] }
500
+ ]
501
+ } ,
502
+ plugins : [
503
+ new HtmlWebpackPlugin ( { hash : true } ) ,
504
+ new MiniCssExtractPlugin ( { filename : 'styles.css' } )
505
+ ]
506
+ } , [ '<link href="styles.css?%hash%"' ] , null , done ) ;
507
+ } ) ;
508
+
509
+ it ( 'should allow to add cache hashes to with the css assets' , done => {
510
+ testHtmlPlugin ( {
511
+ mode : 'production' ,
512
+ entry : path . join ( __dirname , 'fixtures/theme.js' ) ,
513
+ output : {
514
+ path : OUTPUT_DIR ,
515
+ filename : 'index_bundle.js' ,
516
+ publicPath : 'some/'
517
+ } ,
518
+ module : {
519
+ rules : [
520
+ { test : / \. c s s $ / , use : [ MiniCssExtractPlugin . loader , 'css-loader' ] }
521
+ ]
522
+ } ,
523
+ plugins : [
524
+ new HtmlWebpackPlugin ( {
525
+ hash : true ,
526
+ filename : path . resolve ( OUTPUT_DIR , 'subfolder' , 'test.html' )
527
+ } ) ,
528
+ new MiniCssExtractPlugin ( { filename : 'styles.css' } )
529
+ ]
530
+ } , [ '<link href="../styles.css?%hash%"' ] , path . join ( 'subfolder' , 'test.html' ) , done ) ;
531
+ } ) ;
532
+
488
533
it ( 'should inject css files when using the extract text plugin' , done => {
489
534
testHtmlPlugin ( {
490
535
mode : 'production' ,
@@ -550,6 +595,19 @@ describe('HtmlWebpackPlugin', () => {
550
595
} , [ '<link href="styles.css" rel="stylesheet"/>' ] , null , done ) ;
551
596
} ) ;
552
597
598
+ it ( 'prepends the webpack public path to relative path' , done => {
599
+ testHtmlPlugin ( {
600
+ mode : 'production' ,
601
+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
602
+ output : {
603
+ path : OUTPUT_DIR ,
604
+ filename : 'index_bundle.js' ,
605
+ publicPath : 'assets/'
606
+ } ,
607
+ plugins : [ new HtmlWebpackPlugin ( ) ]
608
+ } , [ '<script src="index_bundle.js"' ] , null , done ) ;
609
+ } ) ;
610
+
553
611
it ( 'prepends the webpack public path to script src' , done => {
554
612
testHtmlPlugin ( {
555
613
mode : 'production' ,
@@ -575,7 +633,35 @@ describe('HtmlWebpackPlugin', () => {
575
633
} , [ '<script src="assets/index_bundle.js"' ] , null , done ) ;
576
634
} ) ;
577
635
578
- it ( 'handles subdirectories in the webpack output bundles along with a public path' , done => {
636
+ it ( 'handles subdirectories in the webpack output bundles along with a relative path' , done => {
637
+ testHtmlPlugin ( {
638
+ mode : 'production' ,
639
+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
640
+ output : {
641
+ path : OUTPUT_DIR ,
642
+ filename : 'assets/index_bundle.js' ,
643
+ publicPath : 'some/'
644
+ } ,
645
+ plugins : [ new HtmlWebpackPlugin ( ) ]
646
+ } , [ '<script src="assets/index_bundle.js"' ] , null , done ) ;
647
+ } ) ;
648
+
649
+ it ( 'handles subdirectories in the webpack output bundles along with a relative path' , done => {
650
+ testHtmlPlugin ( {
651
+ mode : 'production' ,
652
+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
653
+ output : {
654
+ path : OUTPUT_DIR ,
655
+ filename : 'assets/index_bundle.js' ,
656
+ publicPath : 'some/'
657
+ } ,
658
+ plugins : [ new HtmlWebpackPlugin ( {
659
+ filename : path . resolve ( OUTPUT_DIR , 'subfolder' , 'test.html' )
660
+ } ) ]
661
+ } , [ '<script src="../assets/index_bundle.js"' ] , path . join ( 'subfolder' , 'test.html' ) , done ) ;
662
+ } ) ;
663
+
664
+ it ( 'handles subdirectories in the webpack output bundles along with a absolute path' , done => {
579
665
testHtmlPlugin ( {
580
666
mode : 'production' ,
581
667
entry : path . join ( __dirname , 'fixtures/index.js' ) ,
@@ -1433,7 +1519,42 @@ describe('HtmlWebpackPlugin', () => {
1433
1519
} , [ / < l i n k r e l = " s h o r t c u t i c o n " h r e f = " \/ s o m e \/ + [ ^ " ] + \. i c o " > / ] , null , done ) ;
1434
1520
} ) ;
1435
1521
1436
- it ( 'adds a favicon with a publichPath set to [hash]/ and replaces the hash' , done => {
1522
+ it ( 'adds a favicon with publicPath set to some/' , done => {
1523
+ testHtmlPlugin ( {
1524
+ mode : 'production' ,
1525
+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
1526
+ output : {
1527
+ path : OUTPUT_DIR ,
1528
+ publicPath : 'some/' ,
1529
+ filename : 'index_bundle.js'
1530
+ } ,
1531
+ plugins : [
1532
+ new HtmlWebpackPlugin ( {
1533
+ favicon : path . join ( __dirname , 'fixtures/favicon.ico' )
1534
+ } )
1535
+ ]
1536
+ } , [ / < l i n k r e l = " s h o r t c u t i c o n " h r e f = " [ ^ " ] + \. i c o " > / ] , null , done ) ;
1537
+ } ) ;
1538
+
1539
+ it ( 'adds a favicon with publicPath set to some/' , done => {
1540
+ testHtmlPlugin ( {
1541
+ mode : 'production' ,
1542
+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
1543
+ output : {
1544
+ path : OUTPUT_DIR ,
1545
+ publicPath : 'some/' ,
1546
+ filename : 'index_bundle.js'
1547
+ } ,
1548
+ plugins : [
1549
+ new HtmlWebpackPlugin ( {
1550
+ favicon : path . join ( __dirname , 'fixtures/favicon.ico' ) ,
1551
+ filename : path . resolve ( OUTPUT_DIR , 'subfolder' , 'test.html' )
1552
+ } )
1553
+ ]
1554
+ } , [ / < l i n k r e l = " s h o r t c u t i c o n " h r e f = " \. \. \/ [ ^ " ] + \. i c o " > / ] , path . join ( 'subfolder' , 'test.html' ) , done ) ;
1555
+ } ) ;
1556
+
1557
+ it ( 'adds a favicon with a publichPath set to /[hash]/ and replaces the hash' , done => {
1437
1558
testHtmlPlugin ( {
1438
1559
mode : 'production' ,
1439
1560
entry : path . join ( __dirname , 'fixtures/index.js' ) ,
@@ -1450,6 +1571,23 @@ describe('HtmlWebpackPlugin', () => {
1450
1571
} , [ / < l i n k r e l = " s h o r t c u t i c o n " h r e f = " \/ [ a - z 0 - 9 ] { 20 } \/ f a v i c o n \. i c o " > / ] , null , done ) ;
1451
1572
} ) ;
1452
1573
1574
+ it ( 'adds a favicon with a publichPath set to [hash]/ and replaces the hash' , done => {
1575
+ testHtmlPlugin ( {
1576
+ mode : 'production' ,
1577
+ entry : path . join ( __dirname , 'fixtures/index.js' ) ,
1578
+ output : {
1579
+ path : OUTPUT_DIR ,
1580
+ publicPath : '[hash]/' ,
1581
+ filename : 'index_bundle.js'
1582
+ } ,
1583
+ plugins : [
1584
+ new HtmlWebpackPlugin ( {
1585
+ favicon : path . join ( __dirname , 'fixtures/favicon.ico' )
1586
+ } )
1587
+ ]
1588
+ } , [ / < l i n k r e l = " s h o r t c u t i c o n " h r e f = " f a v i c o n \. i c o " > / ] , null , done ) ;
1589
+ } ) ;
1590
+
1453
1591
it ( 'adds a favicon with inject enabled' , done => {
1454
1592
testHtmlPlugin ( {
1455
1593
mode : 'production' ,
0 commit comments