From 5af671a7a61e042c58282911b76b4253cb1ee870 Mon Sep 17 00:00:00 2001 From: Eugene Bravov Date: Wed, 29 Jun 2016 15:31:30 +0300 Subject: [PATCH] add extract-text-webpack-plugin support --- EntryTokenParser.php | 21 +++++++++++++-------- README.md | 2 ++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/EntryTokenParser.php b/EntryTokenParser.php index b8bc9f1..d9f4b5c 100644 --- a/EntryTokenParser.php +++ b/EntryTokenParser.php @@ -49,18 +49,23 @@ public function parse(\Twig_Token $token) } $manifest = json_decode(file_get_contents($this->manifestFile), true); + $assets = []; - if (isset($manifest[$entryName])) { - $entry = $manifest[$entryName]; - } elseif (isset($manifest[$entryName.'.js'])) { - $entry = $manifest[$entryName.'.js']; + if (isset($manifest[$entryName.'.js']) || isset($manifest[$entryName.'.css'])) { + if (isset($manifest[$entryName.'.css'])) { + $entryPath = $this->publicPath.$manifest[$entryName.'.css']; + $assets[] = ''; + } + + if (isset($manifest[$entryName.'.js'])) { + $entryPath = $this->publicPath.$manifest[$entryName.'.js']; + $assets[] = ''; + } } else { - throw new \Twig_Error_Loader('Webpack entry '.$entryName.'[.js] not exists.', $token->getLine(), $stream->getFilename()); + throw new \Twig_Error_Loader('Webpack entry '.$entryName.' not exists.', $token->getLine(), $stream->getFilename()); } - $entryPath = $this->publicPath.$entry; - - return new \Twig_Node_Text('', $token->getLine()); + return new \Twig_Node_Text(implode('', $assets), $token->getLine()); } /** diff --git a/README.md b/README.md index e788623..feb86c7 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,5 @@ If you use `[hash]` or `[chunkhash]` in webpack.output You should clear twig cache after each webpack compilation. So for dev environment do not use `[hash]` or `[chunkhash]`. + +#### Works with extract-text-webpack-plugin