Reactjs 网页包--手表不工作
webpack——watch不起作用,但webpack起作用,当我在js中编辑一些更改时,watcher不会在我的DOM(html)中进行任何更新,因此我必须重新启动(再次执行webpack),以便它更新更改 可能存在错误的代码: package.json:Reactjs 网页包--手表不工作,reactjs,webpack,Reactjs,Webpack,webpack——watch不起作用,但webpack起作用,当我在js中编辑一些更改时,watcher不会在我的DOM(html)中进行任何更新,因此我必须重新启动(再次执行webpack),以便它更新更改 可能存在错误的代码: package.json: `{ "name": "samplereact", "version": "1.0.0", "main": "webpack.config.js", "dependencies": { "babel-loader":
`{
"name": "samplereact",
"version": "1.0.0",
"main": "webpack.config.js",
"dependencies": {
"babel-loader": "^6.2.4",
"babel-plugin-add-module-exports": "^0.1.4",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.9.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"core-js": "^2.4.0",
"react": "^0.14.8",
"react-dom": "^0.14.8",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
},
"devDependencies": {},
"scripts": {
"dev": "./node_modules/.bin/webpack-dev-server --content-base src --inline --hot",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
`
webpack.config.js:
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname + "/src",
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
module: {
loaders: [
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy']
}
}
]
},
output: {
path: __dirname + "/src/",
filename: "scripts.min.js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })
]
};
我的文件夹结构如下:
我只把package.json和webpack.config.js放在这里,因为我怀疑只有其中一个是我的手表不工作的原因
顺便说一句,我遵循了本教程(),即使我看了5次,我仍然找不到为什么这只手表不工作的问题。你可能遇到了webpack对路径分隔符的敏感性,这让我痛苦了很多次 技巧是在指定上下文时使用
path.sep
或path.join
而不是/
。所以你要改变这个:
context: __dirname + '/src',
entry: './src/scripts.js',
为此:
context: path.join(__dirname, 'src'),
entry: './scripts.js',
请注意,入口点仍然可以使用
/
,因为它是使用require
解决的,但是上下文
是webpack用于——watch
(另外,您在上下文和入口中都有src
,我认为这是多余的)。您在使用什么操作系统webpack--watch
对路径分隔符非常挑剔,尤其是在Windows上。我使用的是Windows 7,嗯,那么我该怎么做呢?不起作用:(ReferenceError:path没有在Object上定义。(C:\Users\DEV6\Desktop\react\webpack.config.js:7:10)老兄,说真的,这是一个有用的帮助(哈哈,Redunduntuncy的艺术),但我只是添加了一个“var path=require('path');”,因为我知道您所说的是一个方法,谢谢!