如何在 Glitch.com 中导入 npm

问题描述 投票:0回答:1

我正在尝试从“@here/flexpolyline”导入 {decode},它不在 script.js 中运行。

我创建了一个webpack.config.js并创建了一个bundle.js来导入npm,但它仍然不起作用。

https://glitch.com/edit/#!/google-maps-powerapps-iframe

如有任何帮助,我们将不胜感激。

javascript npm webpack glitch-framework
1个回答
0
投票

您会发现,在 Glitch.com 中,您必须使用 Webpack 捆绑 npm 模块,并且该捆绑的结果 (

bundle.js
) 必须正确包含在您的 HTML 中。正确设置
webpack.config.js
后,生成您的
bundle.js
并将其链接到您的
index.html
中。这可能只是引用了一个不存在的文件,或者您的 Webpack 设置不正确。这是一个最小的设置,应该可以让您上路。

webpack.config.js:

const path = require('path');

module.exports = {
  entry: './src/script.js',
  output: {
    path: path.resolve(__dirname, 'public'),
    filename: 'bundle.js',
  },
};

src/script.js:

import { decode } from '@here/flexpolyline';

console.log(decode); // Test your import

index.html:

<script src="/bundle.js"></script>
© www.soinside.com 2019 - 2024. All rights reserved.