Webpack2 Dev Server已刷新,但内容已过时

时间:2016-08-06 20:11:08

标签: webpack webpack-dev-server webpack-2

我有一个使用Webpack2和TypeScript开发的开源项目。

出于某种原因,我的开发服务器启动并且一切都很顺利,但是,当我更改文件时,服务器重新加载正常但不会更新。它在手动和自动刷新时执行此操作。

版本

"webpack": "2.1.0-beta.20",
"webpack-dev-server": "2.1.0-beta.0",

配置

var path = require('path');
var webpack = require('webpack');

var CleanWebpackPlugin = require('clean-webpack-plugin');
var WebpackNotifierPlugin = require('webpack-notifier');
var ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;

var ENV = process.env.NODE_ENV;
var IS_PRODUCTION = ENV === 'production';
var VERSION = JSON.stringify(require('./package.json').version);

function root(args) {
  args = Array.prototype.slice.call(arguments, 0);
  return path.join.apply(path, [__dirname].concat(args));
}

module.exports = {

  context: root(),
  debug: true,
  devtool: 'source-map',

  resolve: {
    extensions: ['', '.ts', '.js', '.json', '.css', '.scss', '.html'],
    // root: root('src'),
    modules: [
      'node_modules',
      root('src')
    ]
  },

  entry: {
    'app': './src/app.ts',
    'polyfills': './src/polyfills.ts',
    'vendor': './src/vendor.ts'
  },

  devServer: {
    // contentBase: './src',
    port: 9999,
    inline: false,
    historyApiFallback: true,
    lazy: false,
    watchOptions: {
      aggregateTimeout: 300,
      poll: 1000
    }
  },

  output: {
    path: root('dist'),
    // publicPath: '/dist/',
    filename: '[name].js',
    sourceMapFilename: '[name].map',
    chunkFilename: '[id].chunk.js'
  },

  module: {
    preLoaders: [
      {
        test: /\.js$/,
        loader: 'source-map'
      },
      {
        test: /\.ts$/,
        loader: 'tslint'
      }
    ],
    loaders: [
      {
        test: /\.ts$/,
        loader: 'awesome-typescript-loader',
        exclude: /(node_modules)/
      },
      {
        test: /\.scss$/,
        loaders: ['style', 'css?sourceMap', 'sass?sourceMap']
      }
    ]
  },

  plugins: [
    new ForkCheckerPlugin(),

    new webpack.optimize.CommonsChunkPlugin({
      name: ['vendor', 'polyfills'],
      minChunks: Infinity
    }),

    new webpack.DefinePlugin({
      'ENV': JSON.stringify(ENV),
      'IS_PRODUCTION': IS_PRODUCTION,
      'APP_VERSION': VERSION
    }),

    new WebpackNotifierPlugin({
      excludeWarnings: true
    }),

    new webpack.optimize.OccurrenceOrderPlugin(true),

    new CleanWebpackPlugin(['dist'], {
      root: root(),
      verbose: false,
      dry: false
    })
  ],

  tslint: {
    emitErrors: false,
    failOnHint: false,
    resourcePath: 'src'
  }
};

项目在这里:https://github.com/swimlane/angular2-data-table

尝试了无数不同的选择并得到了相同的结果。谢谢!

1 个答案:

答案 0 :(得分:1)

原来是导致问题的是ForkCheckerPlugin和Webpack2。删除固定它!