(plugin commonjs) SyntaxError: Unexpected token 当用 rollup 打包 vue 组件时

时间:2021-07-07 05:45:45

标签: javascript typescript vue.js babeljs rollupjs

用rollup打包vue组件时,出现这个错误:

(插件 commonjs)SyntaxError:意外令牌 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()]
};

button.vue:

<template>
  <button>button</button>
</template>
<script lang="ts">
</script>

有什么解决办法吗?

1 个答案:

答案 0 :(得分:0)

我遇到了这样的问题。咒骂 ENV=development jq -n 'env.ENV' 中的任何 html 标签。

<template>

观看此issue