【问题标题】:webpack change path scriptwebpack 更改路径脚本
【发布时间】:2019-02-16 00:59:56
【问题描述】:


最近,我设法将ejs-loaderWebpack 4 一起使用。但是,我开始对 webpack 在启动时在 index.html 中创建的脚本标签遇到问题:<script type="text/javascript" src="main.js"></script>。他的src 不对,因为如果我们查看我的构建,我需要src="/dist/main.js"

node_modules/
dist/
  index.html
  main.js
publics/
src/
views/
server.js
package.json
webpack.config.js

我需要在webpack.congfig.js 中添加什么来创建我想要的 src?

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

module.exports = {
    devtool: 'source-map',

    module: {
        rules: [{
                test: /\.ejs$/,
                use: ['ejs-loader']
            }]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: './views/pages/index.ejs'})
    ]
}

【问题讨论】:

    标签: javascript webpack ejs


    【解决方案1】:
    const HtmlWebpackPlugin = require('html-webpack-plugin');
    
    module.exports = {
        devtool: 'source-map',
        output: {
            publicPath: '/dist/' // <---- this
        },
        module: {
            rules: [{
                    test: /\.ejs$/,
                    use: ['ejs-loader']
                }]
        },
        plugins: [
            new HtmlWebpackPlugin({
                template: './views/pages/index.ejs'})
        ]
    }
    

    【讨论】:

    • 别忘了遮掩解决方案!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 2018-08-03
    • 2019-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    相关资源
    最近更新 更多