【问题标题】:Browser doesn't pickup local file change when running webpack watch运行 webpack watch 时浏览器不会获取本地文件更改
【发布时间】:2018-01-15 16:08:00
【问题描述】:

我尝试使用 webpack2 运行我们的 ASP.NET MVC 项目。作为第一步,我使用 ExtractTextPlugin 设置 webpack2。

运行 webpack watch 时,我可以看到捆绑的 css 文件得到了更新。 但是,如果我使用 IISExpress 运行项目并运行 webpack watch,即使文件已更改,浏览器也不会获取最新更改。

验证如果我关闭 webpack watch 并刷新浏览器,那么我可以在浏览器中看到这些变化。

我在没有 webpack 开发服务器的情况下运行,这里是 webpack.config.js:

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

module.exports = env => {

    return {
        entry: {
            "main": "./static/entry.js",
            "component": path.resolve(__dirname, "../component/static/bundle.js")
        },
        output: {
            path: path.resolve(__dirname, "./static/dist/scripts"),
            filename: "[name].index.js"
        },
        module: {
            rules: [
                {
                    test: /\.scss$/,
				    exclude: /node_modules/,
                    use:ExtractTextPlugin.extract({
                        fallback: "style-loader",
                        use: [
                            { 
                                loader: 'css-loader',
                            },
                            {
                                loader: 'sass-loader',
                                options: {
                                    sourceMap: true,
                                    includePaths: [
                                        path.resolve(__dirname, './default.css'),
                                        path.resolve(__dirname, './normalize.css')
                                    ]
                                }
                            }
                        ]
                    })
                },
                { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ },
                { test: /\.ts$/, loader: 'babel-loader', exclude: /node_modules/ }
            ]
        },
        plugins: [
            new webpack.ProvidePlugin({
                $: path.resolve(__dirname, './node_modules/jquery/src/jquery'),
                jQuery: path.resolve(__dirname, './node_modules/jquery/src/jquery'),
                moment: path.resolve(__dirname, './node_modules/moment/moment')
            }),
            new ExtractTextPlugin({
                filename: "../style/[name].style.css",
                allChunks: true
            }),
            new webpack.optimize.UglifyJsPlugin({
                minimize: true,
                compress: {
                    warnings: false
                }
            })
    ]

    }

};

问题一直存在,我不知道会发生什么,请帮忙。

【问题讨论】:

    标签: asp.net-mvc webpack webpack-2 webpack-style-loader


    【解决方案1】:

    我找到了这个问题的原因。

    项目 web.config 正在缓存客户端资源,禁用输出缓存修复了问题。

    <caching>
      <outputCache enableOutputCache="false" />
    </caching>
    

    【讨论】:

      猜你喜欢
      • 2020-05-15
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2019-07-04
      • 2017-10-08
      • 2019-09-20
      相关资源
      最近更新 更多