鍍金池/ 問(wèn)答/C  網(wǎng)絡(luò)安全  HTML/ webpack-dev-server 只自動(dòng)更新JS文件 其它不更新

webpack-dev-server 只自動(dòng)更新JS文件 其它不更新

我修改less 文件 chrome 控制臺(tái)有提示:

[WDS] Hot Module Replacement enabled.
2app.bundle.js?385c225…:1102 [WDS] App updated. Recompiling...
app.bundle.js?385c225…:1245 [WDS] App hot update...
app.bundle.js?385c225…:754 [HMR] Checking for updates on the server...
app.bundle.js?385c225…:754 [HMR] Nothing hot updated.
app.bundle.js?385c225…:754 [HMR] App is up to date.

但就是不更新, 修改js文件就可以

下面是我寫的代碼

package.json:

{
  "name": "webpacktest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack-dev-server --content-base ./ --open --inline --hot --compress",
    "build": "webpack -d --watch"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "webpack": "^3.10.0"
  },
  "devDependencies": {
    "babel-loader": "^7.1.3",
    "css-loader": "^0.28.10",
    "extract-text-webpack-plugin": "^3.0.2",
    "happypack": "^4.0.1",
    "html-webpack-plugin": "^3.0.4",
    "less": "^3.0.1",
    "less-loader": "^4.0.6",
    "sass": "^1.0.0-beta.5.3",
    "sass-loader": "^6.0.7",
    "style-loader": "^0.20.2",
    "webpack-dev-server": "^2.11.2"
  }
}

webpack.config.js :

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  entry: './src/app.js',
  output: {
    path: __dirname + '/dist',
    filename: 'app.bundle.js'
    //publicPath: '/dist'
  },
  plugins: [
    new HtmlWebpackPlugin({
      minify: {
        collapseWhitespace: true,
      },
      hash: true,
    }),
    new ExtractTextPlugin('style.css')
  ],
  module: {
    rules: [
        {
            test: /\.less$/,
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: ['css-loader', 'less-loader']
            }),
        }
    ]
  },
  devServer: {
    port: 9000
  }
};

app.js :

import css from './app.less';

console.log('hello world');
document.body.innerHTML = 'hello world';

app.less :

@base: #000;


body {
  background: @base;
  color: #fff
  
}
回答
編輯回答
寫榮

這里沒(méi)人嗎 要石沉大海了??

2018年2月8日 03:24