Ehs*_*san 6 javascript typescript vue.js babeljs rollupjs
用rollup打包Vue组件时,出现这样的错误:
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()]
};
Run Code Online (Sandbox Code Playgroud)
按钮.vue:
<template>
<button>button</button>
</template>
<script lang="ts">
</script>
Run Code Online (Sandbox Code Playgroud)
有什么解决办法吗?
所以我找到了更好的方法:
最好使用vue-sfc-rollup来打包 Vue 组件。
2023年更新: 现在Vite很流行,你可以使用Vite Lib模式为NPM打包Vue组件。这是一个可以帮助您的入门模板。
我遇到了这样的问题。咒骂 .html 文件中的任何 html 标签<template>。
plugins: [
vue() //should be the first
babel(),
peerDepsExternal(),
resolve(),
commonjs(),
typescript(),
],
Run Code Online (Sandbox Code Playgroud)
关注本期。
| 归档时间: |
|
| 查看次数: |
6925 次 |
| 最近记录: |