我将 Jhipster 4 与 Angular 2 一起使用,并且需要在我的项目中使用第 3 方库,但是该库不在 npm 上并且没有 .d.ts 文件。我需要直接包含js。 在 vendor.ts 中导入适用于通过 npm 安装的库,但不适用于我的 js,如何在我的项目中使用此文件?
最佳答案
我现在也在尝试解决这个问题..实际上我无法通过将库导入 vendor.ts 文件来通过 yarn 安装库来工作..
我当前的解决方法(...直到我找到正确的方法)是将我需要的 .js 文件复制到 src/main/webapp/content/js/并从 webpack.common 引用它。 CopyWebpackPlugin插件中的js:
在 webpack.common.js 中的插件下,我添加了一个 CopyWebpackPlugin 条目:
new CopyWebpackPlugin([
{ from: './node_modules/core-js/client/shim.min.js', to: 'core-js-shim.min.js' },
{ from: './node_modules/swagger-ui/dist', to: 'swagger-ui/dist' },
{ from: './src/main/webapp/swagger-ui/', to: 'swagger-ui' },
{ from: './src/main/webapp/favicon.ico', to: 'favicon.ico' },
{ from: './src/main/webapp/robots.txt', to: 'robots.txt' },
{ from: './src/main/webapp/i18n', to: 'i18n' },
{ from: './src/main/webapp/content/js/FooLib.js', to: 'FooLib.js'}
]),
然后在 webapp/index.html 添加一个 import
<script src='FooLib.js'></script>
然后在我使用它的组件中声明它:
declare var Foo: any;
关于javascript - 如何在 Jhipster 4 中使用常规的第 3 方 js 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43957003/