webpack-server 2 的问题 [英] issue with webpack-server 2

查看:26
本文介绍了webpack-server 2 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行 webpack 服务器时,它会将我重定向到项目文件夹而不是我的 index.html,但是如果我在没有 webpack 服务器的情况下打开它,它工作正常,并且网络选项卡中没有任何内容.我认为我的 webpack.config.js 没有正确加载!

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!

我的 webpack.confing.js :

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
        })
    ]
}

推荐答案

问题是你误解了与文件系统路径无关的公共路径概念.也就是说,publicPath 只和 url 相关.

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}` 

仅更改/"的提取文本插件参数 publicPath

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

这篇关于webpack-server 2 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆