var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'cheap-module-eval-source-map',
entry: [
'webpack-hot-middleware/client',
'./index.js'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/,
include: __dirname
}
]
}
};
针对Webpack各项配置的介绍
- devtool
- devtool是开发工具,它的作用是生成源代码映射(Source Map),方便调试
- devtool的作用:源代码映射记录了打包编译后的代码和源代码之间的位置对应关系。它可以让你在控制台查找日志(或错误)来源时,直接跳转到源代码中,而不是打包编译后的代码。更多开发工具模式
cheap-module-eval-source-map,这个模式构件速度适中,而且会生成较好的源代码映射,适合在开发环境中使用
- webpack-hot-middleware/client
- 工作原理:先连接上服务器,等着接受需要重新编译代码的通知,一旦代码变动,就会收到通知进而更新客户端代码。
未完待续