[英]Cant get Angular component to work in project, using webpack?
I have created an angular componet (datetime-popup) found here 我创建找到了一个角及部件(日期时间,弹出式) 在这里
I want to be able to use it in my projects, but i cannot get it to work. 我希望能够在我的项目中使用它,但是我无法使其正常工作。 I believe i need to make it a umd library or something with webpack, but i have had a look on this internet and i cannot find how to do this, as whatever i do, it errors.
我相信我需要使它成为一个umd库或带有webpack的东西,但是我已经在这个互联网上看了一下,但是我找不到如何做的方法,因为无论我做什么,都会出错。
Can someone help me to sort this out? 有人可以帮我解决这个问题吗? I would like to be able to reference the project in the demo, and also use it via an external project using npm.
我希望能够在演示中引用该项目,并且还可以通过使用npm的外部项目来使用它。
EDIT: 编辑:
I have tried to duplicate this project but for some reason, when i build my example project, it get an exception in a script 我试图复制该项目,但是由于某种原因,当我构建示例项目时,它在脚本中得到了异常
bundle.js:39725 Uncaught SyntaxError: Unexpected token export
bundle.js:39725 Uncaught SyntaxError:意外的令牌导出
Here is the exception. 这是例外。 This isnt my code and works fine when the ngx-bootstrap project is in the project
这不是我的代码,当ngx-bootstrap项目在项目中时工作正常
Packaging Angular libraries is still a bit of a black art. 打包Angular库仍然有些不道德。 It is on the angular-cli roadmap to provide better out-of-the-box support.
它在angular-cli路线图上可提供更好的现成支持。 Meanwhile, you can consult this excellent overview .
同时,您可以查阅此出色的概述 。
Basically, you need to compile your modules and components with ngc
, based on a tsconfig.json
with specific settings, this being a necessary step in order to create the metadata required by Angular builds, and in-line the templates and CSS (pre-processed if necessary) if they are in external files. 基本上,您需要基于
tsconfig.json
和特定设置,使用ngc
编译模块和组件,这是创建Angular构建所需的元数据并内联模板和CSS的必要步骤(如果它们在外部文件中,则进行必要的处理)。 The consuming application then imports the modules and components from the directory into which they have been compiled, often something like dist
or lib
, which can be accomplished with an entry in package.json
such as "module": "dist/index.js"
. 然后,使用该应用程序的应用程序将从模块和组件的编译目录(通常是
dist
或lib
导入模块和组件,这可以通过package.json
的条目(例如"module": "dist/index.js"
。 If you are publishing to npm
, then you could simply publish the dist
directory. 如果要发布到
npm
,则只需发布dist
目录。 It is beyond the scope of this short answer to provide more exhaustive details. 提供更详尽的细节超出了此简短答案的范围。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.