【问题标题】:webpack using the ejs loaderwebpack 使用 ejs 加载器
【发布时间】:2018-02-16 02:05:25
【问题描述】:

我正在尝试使用 webpack 使用 ejs 重构 HTML 页面。 使用下面的配置,我得到了错误。

模块构建失败:SyntaxError: Unexpected token .

webpack.config.js

const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');


module.exports = {
    context: __dirname + "/src",
    entry: ['./pages/index.ejx'],
    output: {
            path: __dirname + "/dist",
            filename: "[name].bundle.js",
            chunkFilename: "[id].bundle.js"         
    },  
    plugins: [
        new HtmlWebpackPlugin({ template: 'pages/index.ejs'})
    ]
}

index.ejs

<!DOCTYPE html>
<html>
    <% include ..partials/head %>

    <% include ..partials/body %>
</html>

【问题讨论】:

    标签: webpack ejs webpack-2


    【解决方案1】:

    到目前为止,此配置似乎有效:

    const webpack = require('webpack');
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    
    
    module.exports = {
        context: __dirname + "/src",
        entry: ['./index.ejs'],
        output: {
                path: __dirname + "/dist",
                filename: "[name].bundle.js",
                chunkFilename: "[id].bundle.js"         
        },
        module: {
            rules: [
                { test: /\.ejs$/, loader: "ejs-render-loader" } 
    
            ]
        },  
            plugins: [
                new HtmlWebpackPlugin({
                    template: 'index.ejs'
                })
            ]
    }
    

    【讨论】:

    • 索引中有数据吗?喜欢&lt;%- data %&gt;
    猜你喜欢
    • 1970-01-01
    • 2017-02-12
    • 2017-03-23
    • 2021-10-25
    • 2018-12-26
    • 2017-09-08
    • 1970-01-01
    • 2017-01-26
    • 1970-01-01
    相关资源
    最近更新 更多