示例#1
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param PreProcessor\Chain $chain
  * @return void
  */
 public function process(PreProcessor\Chain $chain)
 {
     if ($this->minification->isEnabled(pathinfo($chain->getTargetAssetPath(), PATHINFO_EXTENSION)) && $this->minification->isMinifiedFilename($chain->getTargetAssetPath()) && !$this->minification->isMinifiedFilename($chain->getOrigAssetPath())) {
         $content = $this->adapter->minify($chain->getContent());
         $chain->setContent($content);
     }
 }
示例#2
0
文件: Lite.php 项目: Mohitsahu123/mtf
 /**
  * Get path to minified file for specified original file
  *
  * @param string $originalFile path to original file relative to pub/view_cache
  * @param string $targetFile path relative to pub/view_cache
  * @return void
  */
 public function minifyFile($originalFile, $targetFile)
 {
     if ($this->_isUpdateNeeded($targetFile)) {
         $content = $this->rootDirectory->readFile($originalFile);
         $content = $this->adapter->minify($content);
         $this->pubViewCacheDir->writeFile($targetFile, $content);
     }
 }
 /**
  * Perform actual minification
  *
  * @return void
  */
 protected function minify()
 {
     $isExists = $this->staticViewDir->isExist($this->path);
     if (!$isExists) {
         $shouldMinify = true;
     } elseif ($this->strategy == self::FILE_EXISTS) {
         $shouldMinify = false;
     } else {
         $origlFile = $this->rootDir->getRelativePath($this->originalAsset->getSourceFile());
         $origMtime = $this->rootDir->stat($origlFile)['mtime'];
         $minMtime = $this->staticViewDir->stat($this->path)['mtime'];
         $shouldMinify = $origMtime != $minMtime;
     }
     if ($shouldMinify) {
         $content = $this->adapter->minify($this->originalAsset->getContent());
         $this->staticViewDir->writeFile($this->path, $content);
     }
 }
示例#4
0
    /**
     * @return string
     */
    public function getMinResolverCode()
    {
        $excludes = [];
        foreach ($this->minification->getExcludes('js') as $expression) {
            $excludes[] = '!url.match(/' . str_replace('/', '\\/', $expression) . '/)';
        }
        $excludesCode = empty($excludes) ? 'true' : implode('&&', $excludes);
        $result = <<<code
    if (!require.s.contexts._.__load) {
        require.s.contexts._.__load = require.s.contexts._.load;
        require.s.contexts._.load = function(id, url) {
            if ({$excludesCode}) {
                url = url.replace(/(\\.min)?\\.js\$/, '.min.js');
            }
            return require.s.contexts._.__load.apply(require.s.contexts._, [id, url]);
        }
    }

code;
        if ($this->minification->isEnabled('js')) {
            $result = $this->minifyAdapter->minify($result);
        }
        return $result;
    }