Hal*_*ton 9 javascript webpack webpack-dev-server
所以我设置了webpack webpack-dev-server,但是webpack-dev-server没有自动重新加载.如果我修改文件并保存它,那么在我手动刷新之前,浏览器没有任何变化.
这是我的webpack配置和运行的脚本文件webpack-dev-server.有没有人看到任何可能阻止自动重载工作的东西?
我通过阅读多个教程,文档和阅读react-create-app生成的文件将这些放在一起.
配置/ webpack.config.dev.js
'use strict';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const extractSass = new ExtractTextPlugin('style.css');
module.exports = {
entry : './src/index.jsx',
eslint: {configFile: './src/.eslintrc.json'},
module: {
loaders: [
{
exclude: /node_modules/,
include: ['src'],
loader: 'babel',
test : /(\.js|\.jsx)$/
},
{
exclude: /node_modules/,
include: ['src']
loader : extractSass.extract([ 'css', 'postcss', 'sass' ]),
test : /\.scss$/
}
],
preLoaders: [
{
exclude: /node_modules/,
loader : 'eslint',
query : {presets: [ 'react', 'latest' ]},
test : /(\.js|\.jsx)$/
}
]
},
output: {
filename : 'bundle.js',
path : 'dist',
publicPath: '/'
},
plugins: [
extractSass,
new HtmlWebpackPlugin({
inject : true,
template: paths.appHtml
}),
new webpack.HotModuleReplacementPlugin({multistep: true})
],
postcss: () => [
autoprefixer({
browsers: [
'>1%',
'last 4 versions',
'Firefox ESR',
'not ie < 9'
]
})
]
};
Run Code Online (Sandbox Code Playgroud)
脚本/ dev.js
跟着跑 $ yarn run dev
'use strict';
const WebpackDevServer = require('webpack-dev-server');
const config = require('../config/webpack.config.dev.js');
const webpack = require('webpack');
const compiler = webpack(config);
const server = new WebpackDevServer(compiler, {
clientLogLevel : 'warn',
compress : true,
contentBase : 'public',
filename : config.output.filename,
historyApiFallback: true,
hot : true,
inline : true,
lazy : false,
noInfo : true,
publicPath : '/',
quiet : true,
stats : 'errors-only',
watchOptions : {
aggregateTimeout: 300,
poll : 1000
}
});
server.listen(8080, 'localhost', () => {
console.log('Listening on port 8080');
});
Run Code Online (Sandbox Code Playgroud)
根据webpack dev server 文档,您应该将此入口点添加到 webpack 配置中以支持自动刷新。
config.entry.unshift("webpack-dev-server/client?http://localhost:8080/");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17786 次 |
| 最近记录: |