javascript - 如何将 stenciljs 组件导入到另一个配置了 require 的项目中?
问题描述
我已经开发了一个示例模板组件以在我现有的项目中使用,它具有通过 require js 加载的所有依赖项。我无法导入现有项目。
我在 stencil project's 中尝试了module
value amd
、commonjs
和 targetes3
的不同配置,但它们似乎都不起作用。es5
tsconfig.json
stencil build后,dist
文件夹结构如下:
+ cjs
+ collection
+ esm
+ fonts
+ icons
+ index.js
+ loader
+ types
+ my-component.json
+ my-component
- fvhzbl6z.entry.js
- fvhzbl6z.es5.entry.js
- fvhzbl6z.sc.entry.js
- fvhzbl6zsc.es5.entry.js
- my-component.abuimksq.js
- my-component.u8wgqi9a.js
+ my-component.js /* I'm trying to import this file */
我尝试将文件夹复制my-component
到my-component.js
一个单独的文件夹并my-component.js
在示例 html 文件中引用并且它有效。但是将其导入现有项目会引发错误。
require([
'jquery',
'lib/bluebird',
'lib/mycomponent/my-component'
],
function (
$,
Promise,
MyComponent
) {
'use strict';
/* some stuff here */
}
我收到以下错误:
Running "requirejs:dist" (requirejs) task
Error: Parse error using esprima for file: /Users/sudouser/Downloads/jsproject/dist/tmp/js/lib/stencilcomponent/my-component/fvhzbl6z.entry.js
Error: Line 1: Unexpected token
In module tree:
app
解决方案
推荐阅读
- hook - 为什么 setState 钩子在地图中只设置最后一个对象?
- bison - 使用野牛时 yacc 嵌入操作的问题
- r - 在 R 中使用粘贴动态创建变量名称和值
- ruby-on-rails - rails http 响应 Donwload excel 文件
- go - 在一个 goroutine 中将项目添加到通道并在另一个 goroutine 中处理
- python - 网页抓取,如何接受这个谷歌窗口
- bash - 在 bash 中,如何在变量中捕获一些输出,让休息到达标准输出
- asp.net-core - asp.net core API 条件 URL 重写到不同域
- python - Python Pandas Dataframe Groupby Sum 问题
- java - AWS S3 Java SDK - 通过销售伙伴 (SP) API url 的流下载加密的 GetObject