纯JavaScript可以用React SDK吗?

Can React SDK used in pure JavaScript?

这听起来像是一个微不足道的问题,但我似乎无法从 google 中找到明确的答案。

我已经阅读了有关 SDK 和库的文章。我在阅读中对both.Based有了基本的了解,我将SDK和库总结如下:

图书馆:

Library is a chunk of codes that allows devs to perform certain action for specific task.

SDK:

While SDK is an interface, usually functions that allows the devs to interact with the library. It can also be groups of libraries for certain task 

对于库,根据我的经验,它不是跨 JS 库。例如,在纯 javascipt 库中可能不会使用 react 库。

但是SDK更像是一个接口,是不是意味着SDK是跨JS库的?

也就是说,如果我实现了一个 React SDK,它可以在纯 javascript 中使用吗?反之亦然?

这在技术上是可行的,是的。您可以直接从某些 CDN 导入库来使用它们:

<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>

但是,这真的不推荐,因为您将无法使用 React 拥有的许多强大功能,而这些功能在使用构建系统(即 Webpack)和转译器(即 Babel)时会获得。例如:

您将无法使用 JSX 语法,因此:

return (
    <h1>Greetings, {this.props.name}!</h1>
);

会变成:

return React.createElement('h1', null, 'Greetings, ' + this.props.name + '!');

而且您也无法使用在大多数 React 项目中广泛使用的箭头函数、promises 等 ES6 好东西。

我不建议不使用 JSX 预处理器,但如果你必须编写纯 JS,请遵循此

https://reactjs.org/docs/react-without-jsx.html

还有一个react-pug的实现(pug在express中用来写更好的html带变量) https://github.com/pugjs/babel-plugin-transform-react-pug