我按照这个教程来曝光React作为Webpack的全局变量。已经安装了
Expose
模块并在配置文件webpack.config.js中添加了模块加载器。但是它不起作用,React开发者工具还是无法使用。
以下是我的webpack.config.js文件,第一个加载器是expose-react:
var path = require ('path'),
webpack = require ('webpack'),
htmlWebpackPlugin = require ('html-webpack-plugin');
const PATHS = {
app : path.join (__dirname, 'app'),
build : path.join (__dirname, 'build')
};
module.exports = {
entry : {
main : PATHS.app + '/Main.jsx'
},
output : {
path : PATHS.build,
filename : 'dressAphrodite.js'
},
module : {
loaders : [
{
test : require.resolve ('react'),
loader : 'expose?React'
},
{
test : /\.css$/,
loaders : ['style', 'css'],
include : PATHS.app
},
{
test : /\.js?$/,
loader : 'babel-loader',
include : PATHS.app
},
{
test : /\.jsx?$/,
loader : 'babel-loader',
include : PATHS.app
}
]
},
debug : true,
devtool : 'source-map',
devServer : {
contentBase : './app',
progress : true,
stats : 'errors-only',
},
plugins : [
new htmlWebpackPlugin ({
title : 'Dress',
hash : true
})
]
};
仅供参考,以下是我的package.json文件中安装的依赖项:
{
"name": "dress",
"version": "1.0.0",
"description": "",
"main": "./main.jsx",
"dependencies": {
"i": "^0.3.3",
"npm": "^3.5.2",
"react": "^0.14.3",
"react-dom": "^0.14.3"
},
"devDependencies": {
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0",
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"css-loader": "^0.23.1",
"expose-loader": "^0.7.1",
"html-webpack-plugin": "^1.7.0",
"style-loader": "^0.13.0",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
},
"scripts": {
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC"
}
以下是.babelrc文件的内容:
{
'presets' : [
'es2015',
'react'
]
}
localhost:8080
,不需要/webpack-dev-server
部分。在这里,无需对webpack进行任何其他配置即可正常工作。 - Luis Martins/webpack-dev-server
,页面在更改源代码时将不会自动重新加载。热模块替换(HMR)也将无法工作。最后,“inline”选项已被弃用,并将在下一个主要版本中删除。 - mrbinky3000