[英]Using custom templates with Preact JS
I read the part about using custom templates with preact like我阅读了关于使用自定义模板和 preact 的部分
preact create <username>/<repository> <project-name>
I'm wondering, is there any way I can use this for React templates?我想知道,有什么办法可以将它用于 React 模板? I want to get the CRA-template from https://github.com/facebook/create-react-app/tree/master/packages/cra-template and I couldn't find a good way to do it.
我想从https://github.com/facebook/create-react-app/tree/master/packages/cra-template获取 CRA 模板,但我找不到一个好方法。 I read about a customized version of CRA that is modified to work with Preact, but it fails.
我读到了一个定制版本的 CRA,它被修改为与 Preact 一起使用,但它失败了。
Thanks谢谢
So you're talking about a few different things here.所以你在这里谈论一些不同的事情。
preact create...
is functionality that comes from Preact CLI. preact create...
是来自 Preact CLI 的功能。 Preact CLI is a command line tool for building Preact progressive web applications. Preact CLI 是一个命令行工具,用于构建 Preact 渐进式 web 应用程序。 It is in the same category of a tool as CRA and therefore the two are not compatible.
它与 CRA 属于同一类工具,因此两者不兼容。 You can't use a Preact CLI command to set up a CRA app.
您不能使用 Preact CLI 命令来设置 CRA 应用程序。
If you want to use CRA with Preact you absolutely can though.如果你想将 CRA 与 Preact 一起使用,你绝对可以。 To use Preact with CRA, do the following in a CRA app:
要将 Preact 与 CRA 结合使用,请在 CRA 应用程序中执行以下操作:
Add customize-cra
and react-app-rewired
so you can customize CRA, then Preact so you can, well, use it.添加
customize-cra
和react-app-rewired
rewired 以便您可以自定义 CRA,然后添加 Preact 以便您可以使用它。
yarn add customize-cra react-app-rewired preact
Change your scripts to match:更改您的脚本以匹配:
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test"
},
Finally, create a config-overrides.js
containing the following:最后,创建一个包含以下内容的
config-overrides.js
:
const { override, addWebpackAlias } = require('customize-cra');
module.exports = override(
addWebpackAlias({
'react': 'preact/compat',
'react-dom': 'preact/compat'
})
);
Should be good to go.应该对 go 好。 You can remove
react
and react-dom
from your dependencies.您可以从依赖项中删除
react
和react-dom
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.