Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8879

PHPファイルをhtml-loaderにかけたときにエラーが出るときの対策

$
0
0

PHPプロジェクトをejs(ejs-html-loader)で管理していて、共通ヘッダーのincludeなど、?>で終わらないファイルが存在する場合、productionビルドでエラーが出る

Parse Error: <?php

これは html-loader(正確にはそこから利用される html-minifier-terser)のminimizeオプションでパースエラーとなるため。

これを回避するためには html-loader に continueOnParseError: trueを指定してやれば良い。

webpack.config.js
constExtractTextPlugin=require('extract-text-webpack-plugin');module.exports=[{context:path.resolve(__dirname,'dev'),entry:{// ?> で終わらないファイルを含むindex:'./index.php'.header:'./header.php'},output:{path:path.resolve(__dirname,'public'),filename:'[name].php'},module:{rules:[{test:/\.php/,exclude:/node_modules/,use:ExtractTextPlugin.extract({fallback:"raw-loader",use:[{loader:'html-loader',options:{minimize:{continueOnParseError:true}}},{loader:'ejs-html-loader',options:{context:{// タイムスタンプをPHPファイルに渡すとかtimestamp:+newDate()}}}]})}]},plugins:[newExtractTextPlugin('[name].php')]}];

参考: 【備忘録】HTMLMinifierの全オプションについて調査した


Viewing all articles
Browse latest Browse all 8879

Trending Articles