issue with webpack-server 2

2019-09-16 00:22发布

问题:

When i run webpack server, it redirects me to folders of project not my index.html, but if I open it without webpack server it works fine, and nothing in network tab. I think my webpack.config.js not loaded correctely!

my webpack.confing.js :

    const ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require("path");


module.exports = {
    entry : './src/app.js',
    output : {
        path : path.resolve(__dirname,'dist'),
        filename : 'app.bundle.js'
    },
    module : {
        rules : [
            {test: /\.scss$/, 
            loader: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: ['css-loader','sass-loader'],
                publicPath: "/dist"
            })}
        ]
    },
    plugins: [
        new ExtractTextPlugin({
            filename: "app.scss",
            disable: false,
            allChunks: true
        })
    ]
}

回答1:

The problem is that you have misunderstood the public path concept that has nothing to do with file system path. That is, the publicPath is only related to the url.

url = `${host}:${port}${publicPath}${bundle}` 

Only change your extract text plugin parameter publicPath for '/'