【发布时间】:2020-10-04 06:39:43
【问题描述】:
我已经开始进行模板开发并尝试从中创建 hello world,但是在尝试单独构建和部署和使用它时,dist 文件正在生成一些随机文件,这些文件似乎无法独立工作。
我已将文件发布到 npm 并尝试在 html 文件中独立运行。使用解包 https://unpkg.com/browse/rahulrsingh09-stenciltest2@0.0.2/dist/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<my-component first="FF" last="'Don't call me a framework' JS"></my-component>
<script src='https://unpkg.com/rahulrsingh09-stenciltest2@0.0.2/dist/index.js'></script>
</body>
</html>
这是我在 npm 中找到的另一个包的测试,这似乎有效。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<meta name="author" content="">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<my-component first="FF" last="'Don't call me a framework' JS"></my-component>
<script src='https://unpkg.com/web-component-stencil-test@0.0.1/dist/test.js'></script>
</body>
</html>
我发现的唯一区别是https://unpkg.com/browse/web-component-stencil-test@0.0.1/dist/
dist 包含一个独立运行的项目主体的根文件,但这不是在新的模板配置构建中生成的。这方面的文档非常稀少,有人能指出我在做什么错吗..这里或模板缺少的东西。
package.json
"name": "stenciltest2",
"version": "0.0.2",
"description": "Stencil Component Starter",
"main": "dist/index.cjs.js",
"module": "dist/custom-elements/index.js",
"es2015": "dist/esm/index.mjs",
"es2017": "dist/esm/index.mjs",
"types": "dist/custom-elements/index.d.ts",
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"unpkg": "dist/test/test.js",
"files": [
"dist/",
"loader/"
],
模板配置
import { Config } from '@stencil/core';
export const config: Config = {
namespace: 'test',
buildEs5: true,
outputTargets: [
{
type: 'dist',
esmLoaderPath: '../loader',
},
{
type: 'dist-custom-elements-bundle',
},
{
type: 'docs-readme',
},
{
type: 'www',
serviceWorker: null, // disable service workers
},
]
};
【问题讨论】: