index.js↓
var React = require('react');
var ReactDOM = require('react-dom');
ReactDOM.render(
<h1>Hello World!</h1>,
document.getElementById('example')
);
webpack.config.js↓
var webpack = require('webpack');
var path = require('path');
module.exports={
context: __dirname+'/src',
entry:"./js/index.js",
mondule:{
loaders:[{
test:/\.js?$/,
exclude:/(node_modules)/,
loader:'babel-loader',
query:{
presets:['react','es2015']
}
}]
},
output: {
path: __dirname+"/src/",
filename: "bundle.js"
}
};
package.json↓
{
"name": "react01",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babelify": "^7.3.0",
"create-react-app": "^1.4.0",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"webpack": "^3.5.5",
"webpack-dev-server": "^2.7.1"
}
}
代码我是找着敲的 不过 编辑器我用的是webstorm
在命令行执行webpack的时候 报错
下面是报错信息
Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
- configuration has an unknown property 'mondule'. These properties are valid:
object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, parallelism?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }
For typos: please correct them.
For loader options: webpack 2 no longer allows custom properties in configuration.
Loaders should be updated to allow passing options via loader options in module.rules.
Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
plugins: [
new webpack.LoaderOptionsPlugin({
// test: /\.xxx$/, // may apply this only for some modules
options: {
mondule: ...
}
})
]