javascript - (插件 commonjs) SyntaxError : Unexpected token when packaging vue component with rollup

标签 javascript typescript vue.js babeljs rollupjs

用 rollup 打包一个 Vue 组件时,会出现这个错误:
(plugin commonjs) SyntaxError: Unexpected token
enter image description here
rollup.config.js:

import peerDepsExternal from "rollup-plugin-peer-deps-external";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import vue from "rollup-plugin-vue";
import {babel} from '@rollup/plugin-babel';

import packageJson from "./package.json";

export default {
    input: "src/index.ts",
    output: [
        {
            format: "cjs",
            file: packageJson.main,
            sourcemap: true
        },
        {
            format: "esm",
            file: packageJson.module,
            sourcemap: true
        }
    ],
    plugins: [babel(), peerDepsExternal(), resolve(), commonjs(), typescript(), vue()]
};
按钮.vue:
<template>
  <button>button</button>
</template>
<script lang="ts">
</script>
有什么解决办法吗?
于是我找到了更好的办法:
最好使用vue-sfc-rollup打包 Vue 组件。

最佳答案

我有这样的问题。对 <template> 中的任何 html 标签发誓.

plugins: [
  vue() //should be the first
  babel(),
  peerDepsExternal(),
  resolve(),
  commonjs(),
  typescript(),
],
观看 issue .

关于javascript - (插件 commonjs) SyntaxError : Unexpected token when packaging vue component with rollup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68280645/

相关文章:

html - 如何使用 ngStyle 根据文本字符定位文本元素?

reactjs - Typescript:没有重复项的元组

javascript - 如何在 VueJS 中格式化数字

javascript - 如何使用 vue.js 创建适用于单个元素的显示更多/更少按钮?

javascript - Bootstrap 导航栏菜单项 li a 在特定页面中更改事件类

javascript - 如何在闭包内处理 setInterval 中的 setTimeout

javascript - 禁用按钮不会在 UpdatePanel 中提交回发

node.js - 'ObjectId' 仅指一种类型,但在此处用作值。ts(2693)

javascript - 我可以从 Vuex 商店中的一个突变调用提交吗

javascript - 在没有 cookie 的情况下保留浏览器客户端 javascript/HTML 数据