Skip to content

Commit

Permalink
add extract-text-webpack-plugin support
Browse files Browse the repository at this point in the history
  • Loading branch information
fullpipe committed Jun 29, 2016
1 parent dbad5ce commit 5af671a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 13 additions & 8 deletions EntryTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = '<link rel="stylesheet" href="'.$entryPath.'">';
}

if (isset($manifest[$entryName.'.js'])) {
$entryPath = $this->publicPath.$manifest[$entryName.'.js'];
$assets[] = '<script type="text/javascript" src="'.$entryPath.'"></script>';
}
} 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('<script type="text/javascript" src="'.$entryPath.'"></script>', $token->getLine());
return new \Twig_Node_Text(implode('', $assets), $token->getLine());
}

/**
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5af671a

Please sign in to comment.