Webpack Dev Server 刷新但内容是旧的
Webpack2 Dev Server refreshed but content is old
我有一个正在使用 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
尝试了无数种不同的选择并得到了相同的结果。谢谢!
原来是 ForkCheckerPlugin
和 Webpack2 导致了问题。删除修复它!
我有一个正在使用 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
尝试了无数种不同的选择并得到了相同的结果。谢谢!
原来是 ForkCheckerPlugin
和 Webpack2 导致了问题。删除修复它!