File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ {
2+ "vendor" : {
3+ "js" : " vendor.d4412575.chunk.js"
4+ },
5+ "add" : {
6+ "js" : " add.c1f8097d.min.js"
7+ },
8+ "search" : {
9+ "js" : " search.2e1d3d6d.min.js"
10+ }
11+ }
Original file line number Diff line number Diff line change @@ -33,10 +33,24 @@ public static function getScript($filename)
3333 if (SYSTEMS_REACT_DEV ) {
3434 $ path = "dev/ $ filename.js " ;
3535 } else {
36- $ path = "build/ $ filename.js " ;
36+ $ path = "build/ " . React:: getAssetPath ( $ filename) ;
3737 }
3838 $ script = "<script type='text/javascript' src=' {$ root_directory }$ path'></script> " ;
3939 return $ script ;
4040 }
41+
42+ public static function getAssetPath ($ scriptName )
43+ {
44+ $ rootDirectory = PHPWS_SOURCE_DIR . "mod/systemsinventory/ " ;
45+ if (!is_file ($ rootDirectory . 'assets.json ' )) {
46+ exit ('Missing assets.json file. Run "npm run build" in the systemsinventory directory. ' );
47+ }
48+ $ jsonRaw = file_get_contents ($ rootDirectory . 'assets.json ' );
49+ $ json = json_decode ($ jsonRaw , true );
50+ if (!isset ($ json [$ scriptName ]['js ' ])) {
51+ throw new \Exception ('Script file not found among assets. ' );
52+ }
53+ return $ json [$ scriptName ]['js ' ];
54+ }
4155
4256}
Original file line number Diff line number Diff line change 1212 "@babel/core" : " ^7.1.6" ,
1313 "@babel/preset-env" : " ^7.1.6" ,
1414 "@babel/preset-react" : " ^7.0.0" ,
15+ "assets-webpack-plugin" : " ^3.5.1" ,
1516 "babel-loader" : " ^8.0.5" ,
1617 "browser-sync" : " ^2.26.3" ,
1718 "browser-sync-webpack-plugin" : " ^2.2.2" ,
Original file line number Diff line number Diff line change @@ -75,17 +75,18 @@ module.exports = (env, argv) => {
7575 // require('webpack-bundle-analyzer').BundleAnalyzerPlugin
7676 // settings.plugins.push(new BundleAnalyzerPlugin()) const AssetsPlugin =
7777 // require('assets-webpack-plugin')
78- settings . plugins . push (
79- new webpack . DefinePlugin ( { 'process.env.NODE_ENV' : JSON . stringify ( 'production' ) } )
80- )
78+ const AssetsPlugin = require ( 'assets-webpack-plugin' )
79+ settings . plugins . push (
80+ new webpack . DefinePlugin ( { 'process.env.NODE_ENV' : JSON . stringify ( 'production' ) } )
81+ )
8182
82- // settings.plugins.push( new AssetsPlugin({filename: 'assets.json',
83- // prettyPrint: true, }) )
84- settings . output = {
85- path : setup . path . join ( setup . APP_DIR , 'build' ) ,
86- filename : '[name].js' ,
87- chunkFilename : '[name].js'
88- }
83+ settings . plugins . push ( new AssetsPlugin ( { filename : 'assets.json' ,
84+ prettyPrint : true , } ) )
85+ settings . output = {
86+ path : setup . path . join ( setup . APP_DIR , 'build' ) ,
87+ filename : '[name].[chunkhash:8].min .js' ,
88+ chunkFilename : '[name].[chunkhash:8].chunk .js'
89+ }
8990 }
9091 return settings
9192}
You can’t perform that action at this time.
0 commit comments