htmlWebpackPlugin解析ejs标记错误

时间:2016-08-22 14:27:04

标签: javascript html-webpack-plugin

JS代码

const ejs = require("ejs");
ejs.delimiter = '$';
cms.set("view engine","html");
cms.engine("html",ejs.__express);

ejs代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><$= title $></title>
</head>
<body class="cms-body">
    <div id="root">
    </div>
</body>
</html>

webpack.config.js

new htmlWebpackPlugin({            
    filename: path.join(_rootpath, "/views/home.html"),
    template: path.join(_rootpath, "/views/template/home.ejs"),
    chunks:["vendor","home"],
    minify:{
        collapseWhitespace:true
    }
})

但页面显示:

Html Webpack Plugin:
  Error: Parse Error: <$= title $> 

我想知道HtmlWebpackPlugin如何跳过解析<$= $>

1 个答案:

答案 0 :(得分:0)

如果要解析ejs服务器端,可以重命名

fit1 <- lm(formula = RT ~ RealRatio + InstRatio + RealRatio*InstRatio, data = means_RT)
summary(fit1)

Call:
lm(formula = RT ~ RealRatio + InstRatio + RealRatio * InstRatio, 
data = means_RT)

Residuals:
Min      1Q  Median      3Q     Max 
-85.206 -22.920  -0.381  21.107 105.713 

Coefficients:
                    Estimate Std. Error t value Pr(>|t|)    
(Intercept)         333.807279   9.019529  37.009   <2e-16 ***
RealRatio             0.726752   0.476883   1.524    0.131    
InstRatio            -0.026615   0.471673  -0.056    0.955    
RealRatio:InstRatio  -0.004032   0.015138  -0.266    0.791    

Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 37.48 on 91 degrees of freedom
Multiple R-squared:  0.06734,   Adjusted R-squared:  0.03659 
F-statistic:  2.19 on 3 and 91 DF,  p-value: 0.0946

ggplot(means_RT, aes(x= RealRatio, y=RT,  fill=InstRatio)) + 
  geom_bar(binwidth = 1.5, alpha = .5, position = "identity")

并重命名

/views/template/home.ejs

/views/template/home.html

然后将您的视图引擎更改为ejs。