簡體   English   中英

每次看到更改我都必須清除緩存並刷新

[英]Every time to see changes I have to clear cache and refresh

webpack.config.js :

const path = require('path')
const config = require('config')
const CopyWebpackPlugin = require('copy-webpack-plugin')


module.exports = {
    entry: './public/clientMain.js',
    node: { 
        fs: 'empty' 
    },
    output: {
        filename: 'app-v' + config.VERSION + '.js',
        libraryTarget: 'var',
        library: 'start',
        path: path.resolve(__dirname, './build/js')
    },
    module: {
        loaders: [{
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader'
        }]
    },
    watchOptions: {
        ignored: /node_modules/,
    },   
    plugins: [
        new CopyWebpackPlugin([
          { from: 'public/assets', to: '../assets' }
        ])
    ]
}

package.json 中

"scripts": {
   "start": "concurrently \"node ./node_modules/webpack/bin/webpack.js -d --watch\" \"nodemon ./server/serverMain.js \" \"node ./node_modules/http-server/bin/http-server -p 8080\""

},

問題是每次我對其中一個 js 文件進行更改時,我都必須清除瀏覽器中的緩存,然后刷新頁面以查看更改! 硬重載或ofc Empty Cache和chrome中的硬重載

我想這不正常嗎? 那么我該如何解決這個問題?

正確的方法是在輸出文件名中添加一個哈希值。

 output: {
        filename: 'app-v.[hash].' + config.VERSION + '.js',
    },

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM