webpack --watch不起作用,但是webpack没有,当我在js中编辑一些更改时,观察者不会在我的DOM(html)中进行任何更新,所以我将不得不重新启动(再次执行webpack)以便它将更新更改。
可能有错误的代码:
的package.json:
`{
"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放在这里,因为我怀疑其中只有一个是我手表无法工作的原因。
btw我遵循了这个教程(https://www.youtube.com/watch?v=MhkGQAoc7bc),甚至“我看了5次,我仍然无法找到问题,为什么这只手表不起作用。”
答案 0 :(得分:1)
你可能会遇到webpack对路径分隔符的敏感性,它已经多次咬过我。
诀窍是在指定上下文时使用=If([EWFMCodeSelect]="BREAK") Then Sum([TimeDiff (ToInt)]ForEach([Clndr Date];[Time-Interval];[Agent Login];[Code]))
ElseIf([EWFMCodeSelect]="DISC") Then Sum([TimeDiff (ToInt)]ForEach([Clndr Date];[Time-Interval];[Agent Login];[Code]))
ElseIf([EWFMCodeSelect]="MISS") Then Sum([TimeDiff (ToInt)]ForEach([Clndr Date];[Time-Interval];[Agent Login];[Code]))
ElseIf([EWFMCodeSelect]="NEUTR") Then Sum([TimeDiff (ToInt)]ForEach([Clndr Date];[Time-Interval];[Agent Login];[Code]))
ElseIf([EWFMCodeSelect]="NODISC") Then Sum([TimeDiff (ToInt)]ForEach([Clndr Date];[Time-Interval];[Agent Login];[Code]))
ElseIf([EWFMCodeSelect]="SHIFT") Then Sum([TimeDiff (ToInt)]ForEach([Clndr Date];[Time-Interval];[Agent Login];[Code]))
或path.sep
而不是path.join
。所以你要改变这个:
/
到此:
context: __dirname + '/src',
entry: './src/scripts.js',
请注意,该入口点仍然可以使用context: path.join(__dirname, 'src'),
entry: './scripts.js',
,因为它已使用./
解析,但require
是webpack用于context
的内容,你在上下文和条目中都有--watch
,我认为这是多余的。