【发布时间】:2018-04-13 14:05:53
【问题描述】:
我正在尝试使用 HyperHTMLElement 定义一个简单的自定义元素,但我似乎无法在没有来自 Chrome(以及 Safari)的投诉的情况下使用 extend HyperHTMLElement。
src/index.js
import 'document-register-element'
import HyperHTMLElement from 'hyperhtml-element/esm'
const { bind } = HyperHTMLElement
class Hello extends HyperHTMLElement {
created() { this.textContent = 'hello' }
}
Hello.define('hello-element')
bind(document.body)`<hello-element />`
rollup.config.js
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'
export default {
input: 'src/index.js',
output: [{ file: 'bundle.js', sourcemap: 'inline', format: 'iife', name: 'oye' }],
plugins: [
babel({
exclude: 'node_modules/**',
presets: [ ["env", { "modules": false }] ],
plugins: [ "external-helpers" ]
}),
nodeResolve({ module: true, jsnext: true, main: true, browser: true }),
commonjs(),
]
}
index.html:
<!DOCTYPE html>
<html>
<head></head>
<body>
<script type="text/javascript" src="bundle.js"></script>
</body>
</html>
Rollup 将所有内容无误地捆绑在一起:
但是,Chrome 会报告这一点:
我也尝试切换到 Webpack+Babel,但无济于事 - 仍然报告相同的堆栈跟踪(与 Webpack 特定的细微差别)。
【问题讨论】:
标签: ecmascript-6 babeljs es6-class rollup hyperhtml