Polymer bundler 不输出带有自定义包的 node_modules 文件夹
Polymer bundler does not output node_modules folder with custom bundles
使用 polymer-cli
1.7.7,捆绑支持 esm、es6 和 es5 的 Polymer 3 应用程序不会输出 node_modules
。因此,当使用 prpl-server
.
提供捆绑包时,找不到诸如 @webcomponents/webcomponentsjs
之类的依赖项
这里有一个小例子可以复现:
https://github.com/lpellegr/polymer-bundler-bundle-issue
本例基于polymer-cli init
生成的原始polymer 3 app模板。配置文件 polymer.json
已编辑为生成 esm、es6 和 es5 包,如以下资源中所建议:
https://polymer.github.io/pwa-starter-kit/building-and-deploying/
如果您 运行 polymer build
,输出目录不包含 node_modules
目录,因此不包含 webcomponentjs 的 JavaScript 文件:
build/
├── es5-bundled
│ ├── index.html
│ ├── push-manifest.json
│ ├── service-worker.js
│ └── src
│ └── _element
│ └── _element.js
├── es6-bundled
│ ├── index.html
│ ├── push-manifest.json
│ ├── service-worker.js
│ └── src
│ └── _element
│ └── _element.js
├── esm-bundled
│ ├── index.html
│ ├── push-manifest.json
│ ├── service-worker.js
│ └── src
│ └── _element
│ └── _element.js
└── polymer.json
如果您从 polymer.json
中删除 builds
选项(从而恢复为默认模板),那么一切看起来都不错,输出正确的 node_modules
文件夹:
build/ └── default
├── index.html
├── node_modules
│ ├── @polymer
│ │ └── polymer
│ │ ├── lib
│ │ │ ├── elements
│ │ │ │ └── dom-module.js
│ │ │ ├── mixins
│ │ │ │ ├── element-mixin.js
│ │ │ │ ├── properties-changed.js
│ │ │ │ ├── properties-mixin.js
│ │ │ │ ├── property-accessors.js
│ │ │ │ ├── property-effects.js
│ │ │ │ └── template-stamp.js
│ │ │ └── utils
│ │ │ ├── async.js
│ │ │ ├── boot.js
│ │ │ ├── case-map.js
│ │ │ ├── html-tag.js
│ │ │ ├── mixin.js
│ │ │ ├── path.js
│ │ │ ├── resolve-url.js
│ │ │ ├── settings.js
│ │ │ └── style-gather.js
│ │ └── polymer-element.js
│ └── @webcomponents
│ └── webcomponentsjs
│ └── webcomponents-loader.js
└── src
├── _element
│ └── _element.js
└── test-app
└── test-app.js
我的polymer.json
有问题吗?这是 polymer-bundler
的错误吗?
您的 polymer.json
文件不包含 Polymer CLI 用来决定要包含在构建中的内容的信息。
根据 PWA 初学者工具包添加缺失的行使其工作,例如:
"entrypoint": "index.html",
"extraDependencies": [
"node_modules/@webcomponents/webcomponentsjs/**"
],
使用 polymer-cli
1.7.7,捆绑支持 esm、es6 和 es5 的 Polymer 3 应用程序不会输出 node_modules
。因此,当使用 prpl-server
.
@webcomponents/webcomponentsjs
之类的依赖项
这里有一个小例子可以复现:
https://github.com/lpellegr/polymer-bundler-bundle-issue
本例基于polymer-cli init
生成的原始polymer 3 app模板。配置文件 polymer.json
已编辑为生成 esm、es6 和 es5 包,如以下资源中所建议:
https://polymer.github.io/pwa-starter-kit/building-and-deploying/
如果您 运行 polymer build
,输出目录不包含 node_modules
目录,因此不包含 webcomponentjs 的 JavaScript 文件:
build/
├── es5-bundled
│ ├── index.html
│ ├── push-manifest.json
│ ├── service-worker.js
│ └── src
│ └── _element
│ └── _element.js
├── es6-bundled
│ ├── index.html
│ ├── push-manifest.json
│ ├── service-worker.js
│ └── src
│ └── _element
│ └── _element.js
├── esm-bundled
│ ├── index.html
│ ├── push-manifest.json
│ ├── service-worker.js
│ └── src
│ └── _element
│ └── _element.js
└── polymer.json
如果您从 polymer.json
中删除 builds
选项(从而恢复为默认模板),那么一切看起来都不错,输出正确的 node_modules
文件夹:
build/ └── default
├── index.html
├── node_modules
│ ├── @polymer
│ │ └── polymer
│ │ ├── lib
│ │ │ ├── elements
│ │ │ │ └── dom-module.js
│ │ │ ├── mixins
│ │ │ │ ├── element-mixin.js
│ │ │ │ ├── properties-changed.js
│ │ │ │ ├── properties-mixin.js
│ │ │ │ ├── property-accessors.js
│ │ │ │ ├── property-effects.js
│ │ │ │ └── template-stamp.js
│ │ │ └── utils
│ │ │ ├── async.js
│ │ │ ├── boot.js
│ │ │ ├── case-map.js
│ │ │ ├── html-tag.js
│ │ │ ├── mixin.js
│ │ │ ├── path.js
│ │ │ ├── resolve-url.js
│ │ │ ├── settings.js
│ │ │ └── style-gather.js
│ │ └── polymer-element.js
│ └── @webcomponents
│ └── webcomponentsjs
│ └── webcomponents-loader.js
└── src
├── _element
│ └── _element.js
└── test-app
└── test-app.js
我的polymer.json
有问题吗?这是 polymer-bundler
的错误吗?
您的 polymer.json
文件不包含 Polymer CLI 用来决定要包含在构建中的内容的信息。
根据 PWA 初学者工具包添加缺失的行使其工作,例如:
"entrypoint": "index.html",
"extraDependencies": [
"node_modules/@webcomponents/webcomponentsjs/**"
],