简体   繁体   English

webpack更改路径脚本

[英]webpack change path script


Recently, I managed to use ejs-loader with Webpack 4 . 最近,我设法将ejs-loaderWebpack 4一起使用。 But, I started to get trouble with the script tag that webpack create into index.html when it launch : <script type="text/javascript" src="main.js"></script> . 但是,我开始遇到webpack启动时在index.html中创建的脚本标记的问题: <script type="text/javascript" src="main.js"></script> His src is not right because if we look my build I need src="/dist/main.js" : 他的src不正确,因为如果我们查看我的构建,则需要src="/dist/main.js"

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

What I need to add into my webpack.congfig.js to create a src like I want ? 我需要添加到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'})
    ]
}
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'})
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM