1
我是webpack的新手,我無法設置如何在我的代碼中更改內容時使webpack監視我的文件。 換句話說,我希望每次在我的代碼中進行更改時都會重新加載頁面。Webpack - 如何設置熱加載(觀看文件)
我讀過幾篇關於如何做的博客,但我似乎無法讓它工作。 截至目前,我可以捆綁它並將其託管在我的本地主機上,而不會出現問題。
這是我到目前爲止有:
webpack.config.js
module.exports = {
entry: [
'./src/index.js'
],
watch: true,
output: {
path: __dirname,
publicPath: '/',
filename: 'bundle.js'
},
module: {
loaders: [{
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-1']
}
}]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
devServer: {
historyApiFallback: true,
contentBase: './'
}
};
的package.json
{
"name": "simple-app",
"version": "1.0.0",
"description": "demo",
"main": "index.js",
"repository": "",
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-react": "^6.1.18",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"jquery": "^2.2.1",
"jsdom": "^8.1.0",
"mocha": "^2.4.5",
"react-addons-test-utils": "^0.14.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.16.2"
},
"dependencies": {
"babel-preset-stage-1": "^6.1.18",
"lodash": "^3.10.1",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-redux": "^4.0.0",
"react-router": "^2.0.1",
"redux": "^3.0.4",
"redux-thunk": "^2.1.0"
}
}
不是答案,但您不需要包含'node。/ node_modules/webpack-dev-server/bin/webpack-dev-server.js'。你可以做''start':「webpack-dev-server」' –