javascript - Add dist file from npm package to build
问题描述
I'm using the node-poweredup npm package in my react based project. I provides a nodejs and a browser version of the library. The browser version is available from the jsdelivr CDN and this is also how I add this library to my react app - I simply include the poweredup.js in a script tag in the index.html.
I can see that the node-poweredup module has a the same file in its dist/browser
folder (node_modules/node-poweredup/dist/browser/poweredup.js
). How can I copy this js file to my build directory when running yarn build
so that I can use this one instead of the one from the CDN?
I have a standard react app created with create-react-app
.
解决方案
尝试正常导入。删除 CDN。react-scripts 会在构建过程中打包文件。
如果问题仍然存在,请将整个目录 node_modules/node-poweredup 复制到 node_modules 之外并执行绝对导入。
import * from './node-poweredup/${path}'
提供模块所在的路径
或者,更好的是下载 CDN 并使用 script 标签导入 index.js
推荐阅读
- ios - Swift Dispatch Main 同步使 UIView 动画混乱
- mongodb - MongoTemplate.getCollectionNames 和 MongoTemplate,collectionExists 方法在连接到 Azure Cosmos DB 时抛出 StringIndexOutOfBoundsException
- python - Python:dict的键/值对子集确定要调用的函数
- javascript - 提供角度的功能
- python - ValueError:条件预期的布尔数组,而不是对象
- python-3.x - Python 正则表达式在 2 个边缘案例上失败
- postgresql - PostgresSQL嵌套jsonb更新复杂键/值对的值
- java - 使用 if 语句从一副牌中抽出特定的牌
- javascript - 从 JSON 嵌套对象键中获取值
- r - 如何在 R Markdown 中打印星号('*')