1414 */
1515
1616const PluginPriorities = require ( './plugin-priorities' ) ;
17- const copyEntryTmpName = require ( '../utils/copyEntryTmpName' ) ;
18- const AssetsPlugin = require ( 'assets-webpack-plugin' ) ;
19- const fs = require ( 'fs' ) ;
20- const path = require ( 'path' ) ;
21- const crypto = require ( 'crypto' ) ;
22-
23- function processOutput ( webpackConfig ) {
24- return ( assets ) => {
25- // Remove temporary entry added by the copyFiles feature
26- delete assets [ copyEntryTmpName ] ;
27-
28- // with --watch or dev-server, subsequent calls will include
29- // the original assets (so, assets.entrypoints) + the new
30- // assets (which will have their original structure). We
31- // delete the entrypoints key, and then process the new assets
32- // like normal below. The same reasoning applies to the
33- // integrity key.
34- delete assets . entrypoints ;
35- delete assets . integrity ;
36-
37- // This will iterate over all the entry points and convert the
38- // one file entries into an array of one entry since that was how the entry point file was before this change.
39- const integrity = { } ;
40- const integrityAlgorithms = webpackConfig . integrityAlgorithms ;
41- const publicPath = webpackConfig . getRealPublicPath ( ) ;
42-
43- for ( const asset in assets ) {
44- for ( const fileType in assets [ asset ] ) {
45- if ( ! Array . isArray ( assets [ asset ] [ fileType ] ) ) {
46- assets [ asset ] [ fileType ] = [ assets [ asset ] [ fileType ] ] ;
47- }
48-
49- if ( integrityAlgorithms . length ) {
50- for ( const file of assets [ asset ] [ fileType ] ) {
51- if ( file in integrity ) {
52- continue ;
53- }
54-
55- const filePath = path . resolve (
56- webpackConfig . outputPath ,
57- file . replace ( publicPath , '' )
58- ) ;
59-
60- if ( fs . existsSync ( filePath ) ) {
61- const fileHashes = [ ] ;
62-
63- for ( const algorithm of webpackConfig . integrityAlgorithms ) {
64- const hash = crypto . createHash ( algorithm ) ;
65- const fileContent = fs . readFileSync ( filePath , 'utf8' ) ;
66- hash . update ( fileContent , 'utf8' ) ;
67-
68- fileHashes . push ( `${ algorithm } -${ hash . digest ( 'base64' ) } ` ) ;
69- }
70-
71- integrity [ file ] = fileHashes . join ( ' ' ) ;
72- }
73- }
74- }
75- }
76- }
77-
78- const manifestContent = { entrypoints : assets } ;
79- if ( integrityAlgorithms . length ) {
80- manifestContent . integrity = integrity ;
81- }
82-
83- return JSON . stringify ( manifestContent , null , 2 ) ;
84- } ;
85- }
17+ const { EntryPointsPlugin } = require ( '../webpack/entry-points-plugin' ) ;
8618
8719/**
8820 * @param {Array } plugins
@@ -91,13 +23,11 @@ function processOutput(webpackConfig) {
9123 */
9224module . exports = function ( plugins , webpackConfig ) {
9325 plugins . push ( {
94- plugin : new AssetsPlugin ( {
95- path : webpackConfig . outputPath ,
96- filename : 'entrypoints.json' ,
97- includeAllFileTypes : true ,
98- entrypoints : true ,
99- processOutput : processOutput ( webpackConfig )
26+ plugin : new EntryPointsPlugin ( {
27+ publicPath : webpackConfig . getRealPublicPath ( ) ,
28+ outputPath : webpackConfig . outputPath ,
29+ integrityAlgorithms : webpackConfig . integrityAlgorithms
10030 } ) ,
101- priority : PluginPriorities . AssetsPlugin
31+ priority : PluginPriorities . EntryPointsPlugin
10232 } ) ;
10333} ;
0 commit comments