2016-11-08 26 views
1

由于某些原因,我无法让webpack在变更时重建我的文件。我基本上遵循了Browsersync - Webpack + TypeScript RecipeWebpack不能在变更时重建

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" 
}, 

每当我在01中更改打印稿文件没有任何反应。 我在这里做错了什么?

回答

2

通过明确地将watch部分添加到webpack dev中间件配置来修复它。

如这里要求的是配置变化:

browserSync.init({ 
    ... 
    middleware: [ 
    webpackDevMiddleware(bundler, { 
     // Explicitly set watch options: 
     watchOptions: { 
     aggregateTimeout: 300, 
     poll: true 
     } 
    }) 
    ] 
}); 
+0

你能分享你的配置文件 – Neil

+1

@Neil你去那里的实际变化:) – Bob