55
66class RequireJsPlugin
77{
8- // protected $scopeConfig;
9- //
10- // public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
11- // {
12- // $this->scopeConfig = $scopeConfig;
13- // }
8+ protected $ scopeConfig ;
9+
10+ public function __construct (\Magento \Framework \App \Config \ScopeConfigInterface $ scopeConfig )
11+ {
12+ $ this ->scopeConfig = $ scopeConfig ;
13+ }
1414
1515 public function aroundAddFile (RequireJs $ subject , callable $ proceed , $ filePath , $ sourcePath , $ contentType ) {
1616
17- // $jsOptimization = $this->scopeConfig->getValue('mfrocketjavascript/enable_javaScript_bundling_optimization', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
18- // var_dump($jsOptimization); exit();
17+ $ jsOptimization = $ this ->scopeConfig ->getValue ('mfrocketjavascript/general/enable_javaScript_bundling_optimization ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
18+ if ($ jsOptimization ) {
19+ $ includeInBundling = $ this ->scopeConfig ->getValue ('mfrocketjavascript/general/included_in_bundling ' , \Magento \Store \Model \ScopeInterface::SCOPE_STORE );
20+ $ allowedFiles = str_replace ("\r" ,"\n" , $ includeInBundling );
21+ $ allowedFiles = explode ("\n" , $ allowedFiles );
22+
23+ foreach ($ allowedFiles as $ key => $ allowedFile ) {
24+ $ allowedFiles [$ key ] = trim ($ allowedFile );
25+ if (empty ($ allowedFiles [$ key ])) {
26+ unset($ allowedFiles [$ key ]);
27+ }
28+ }
29+
30+ foreach ($ allowedFiles as $ allowed ) {
31+ $ allowedFiles [] = str_replace ('.min.js ' , '.js ' , $ allowed );
32+ }
33+
34+ $ include = false ;
35+ foreach ($ allowedFiles as $ allowedFile ) {
36+ if (strpos ($ sourcePath , $ allowedFile ) !== false ) {
37+ $ include = true ;
38+ break ;
39+ }
40+ }
41+
42+ if (!$ include ) {
43+ return true ;
44+ }
45+
46+ }
1947 return $ proceed ($ filePath , $ sourcePath , $ contentType );
2048 }
2149}
0 commit comments