diff --git a/src/Bundle/Twig/Token/WebpackTokenParser.php b/src/Bundle/Twig/Token/WebpackTokenParser.php index b196367..8f1430f 100644 --- a/src/Bundle/Twig/Token/WebpackTokenParser.php +++ b/src/Bundle/Twig/Token/WebpackTokenParser.php @@ -4,6 +4,7 @@ use Hostnet\Bundle\WebpackBundle\Twig\Node\WebpackInlineNode; use Hostnet\Bundle\WebpackBundle\Twig\Node\WebpackNode; use Hostnet\Bundle\WebpackBundle\Twig\TwigExtension; +use Hostnet\Component\Webpack\Asset\TwigParser; /** * @author Harold Iedema @@ -130,7 +131,7 @@ private function parseInline(\Twig_TokenStream $stream, $lineno) $this->inline_blocks[$file] = 0; } - $file_name = md5($file . $this->inline_blocks[$file]) . '.js'; + $file_name = TwigParser::hashInlineFileName($file, $this->inline_blocks[$file]) . '.js'; $assets = $this->extension->webpackAsset('cache.' . $file_name); $this->inline_blocks[$file]++; diff --git a/src/Component/Asset/TwigParser.php b/src/Component/Asset/TwigParser.php index f42a00b..716c9eb 100644 --- a/src/Component/Asset/TwigParser.php +++ b/src/Component/Asset/TwigParser.php @@ -25,6 +25,23 @@ public function __construct(Tracker $tracker, \Twig_Environment $twig, $cache_di $this->cache_dir = $cache_dir; } + /** + * Consistently calculate file name hashes. + * + * @param $template_file + * @param $block_index + * @return string + */ + public static function hashInlineFileName($template_file, $block_index) + { + // Work around path inconsistencies on Windows/XAMPP. + if (DIRECTORY_SEPARATOR == '\\') { + $template_file = str_replace('\\', '/', $template_file); + } + $hash = md5($template_file . $block_index); + return $hash; + } + /** * Returns an array of split points from the given template file. * @@ -53,7 +70,7 @@ public function findSplitPoints($template_file) $stream->next(); $token = $stream->next(); - $file_name = md5($template_file . $inline_blocks); + $file_name = TwigParser::hashInlineFileName($template_file, $inline_blocks); // Are we dealing with a custom extension? If not, fallback to javascript. $extension = 'js'; // Default