首页 > 解决方案 > 如何将 stenciljs 组件导入到另一个配置了 require 的项目中?

问题描述

我已经开发了一个示例模板组件以在我现有的项目中使用,它具有通过 require js 加载的所有依赖项。我无法导入现有项目。

我在 stencil project's 中尝试了modulevalue amdcommonjs和 targetes3的不同配置,但它们似乎都不起作用。es5tsconfig.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-componentmy-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

标签: javascriptrequirejsamdtsconfigstenciljs

解决方案


推荐阅读