出于某种原因,我无法让webpack在更改时重建我的文件。我基本上遵循了Browsersync - Webpack + TypeScript Recipe。
我的webpack.config.js
:
let path = require('path');
let webpack = require('webpack');
let config = {
debug: true,
devtool: 'eval',
entry: './app/index.ts',
output: {
publicPath: '/',
path: path.join(__dirname, 'wwwroot'),
filename: 'bundle.js'
},
plugins: [],
resolve: {
extensions: ['', '.ts', '.js']
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts', include: path.join(__dirname, 'app') }
]
}
};
module.exports = config;
我从配方中复制的浏览器同步配置(server.js
):
var browserSync = require('browser-sync').create();
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var stripAnsi = require('strip-ansi');
var webpackConfig = require('./webpack.config');
var bundler = webpack(webpackConfig);
bundler.plugin('done', function (stats) {
if (stats.hasErrors() || stats.hasWarnings()) {
return browserSync.sockets.emit('fullscreen:message', {
title: "Webpack Error:",
body: stripAnsi(stats.toString()),
timeout: 100000
});
}
browserSync.reload();
});
browserSync.init({
server: 'wwwroot',
open: false,
logFileChanges: false,
middleware: [
webpackDevMiddleware(bundler, {
publicPath: webpackConfig.output.publicPath,
stats: {colors: true}
})
],
plugins: ['bs-fullscreen-message'],
files: [
]
});
要启动它,我只需使用npm脚本部分:
"scripts": {
"build": "node server"
},
每当我更改app/
中的打字稿文件时,都没有任何反应。
我在这里做错了什么?
答案 0 :(得分:2)
通过将watch部分显式添加到webpack dev中间件配置来修复它。
这里要求的是配置更改:
browserSync.init({
...
middleware: [
webpackDevMiddleware(bundler, {
// Explicitly set watch options:
watchOptions: {
aggregateTimeout: 300,
poll: true
}
})
]
});