📅  最后修改于: 2023-12-03 15:09:40.622000             🧑  作者: Mango
Postlight 的 WordPress + React Starter Kit 是一个基于 WordPress 和 React 的开发工具包,可以帮助开发者快速搭建可扩展、易于维护的 WordPress 主题。
该工具包包含了一系列的开发工具和工作流程,以便开发者能够更快地构建出高质量的 WordPress 主题。
npm install
npm start
npm run build
./build
文件夹中的文件部署到 WordPress 主题目录中即可。import React, { Component } from 'react';
class PostList extends Component {
state = {
posts: []
}
componentDidMount() {
fetch('/wp-json/wp/v2/posts')
.then(res => res.json())
.then(posts => this.setState({ posts }));
}
render() {
const { posts } = this.state;
return (
<ul>
{posts.map(post => (
<li key={post.id}>
<h3 dangerouslySetInnerHTML={{ __html: post.title.rendered }} />
<p dangerouslySetInnerHTML={{ __html: post.excerpt.rendered }} />
<a href={post.link}>Read more</a>
</li>
))}
</ul>
);
}
}
export default PostList;
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new webpack.HotModuleReplacementPlugin()
],
devServer: {
contentBase: './build',
hot: true
}
};