我正在尝试按照反应教程,我的webpack.config.js文件如下:
var webpack = require("webpack");
var pth = require("path");
module.exports = {
entry: "./src/index.js",
output: {
path: __dirname + "/dist",
filename: "bundle.js"
},
devServer: {
inline: true,
contentBase: './dist',
port: 3000
},
module: {
rules: [
{ test: /\.js$/, exclude: /(node_modules)/, use: 'babel-loader' },
{ test: /\.json$/, exclude: /(node_modules)/, use: 'json-loader' }
]
}
}
Run Code Online (Sandbox Code Playgroud)
虽然我的代码文件如下:我在lib.js中创建了组件,并且在index.js中完成了渲染,最终在index.html的HTML div中调用
lib.js
import React from 'react'
import text from './titles.json'
export const hello = (
<h1 id='title'
className='header'
style={{backgroundColor: 'purple', color: 'yellow'}}>
{text.hello}
</h1> …Run Code Online (Sandbox Code Playgroud)