gpt4 book ai didi

javascript - 仅使用 babel 构建 typescript vue 应用程序?

转载 作者:行者123 更新时间:2023-12-01 15:21:17 24 4
gpt4 key购买 nike

如何仅使用 babel 编译和构建我的 typescript vue 应用程序?我广泛使用了 vue-cli-service,但达到了我只需要最小设置的地步,没有 webpack 或任何东西。
我的.babelrc

{
"presets": ["babel-preset-typescript-vue"],
"plugins": ["@babel/plugin-transform-typescript"]
}
我的 package.json 依赖项:
"devDependencies": {
"@babel/cli": "^7.10.5",
"@babel/plugin-transform-typescript": "^7.11.0",
"@babel/preset-env": "^7.11.0",
"babel-loader": "^8.1.0",
"babel-preset-env": "^1.7.0",
"babel-preset-typescript-vue": "^1.1.1",
"typescript": "~3.9.3",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"vue": "^2.6.12",
"vue-class-component": "^7.2.3",
"vue-property-decorator": "^8.4.2",
"vuex": "^3.5.1"
}
我的条目 main.ts 文件:
import Vue from 'vue'
import Vuex from 'vuex';
import App from './App.vue'

Vue.config.productionTip = false;
Vue.use(Vuex);

new Vue({render: h => h(App)}).$mount('#app');
我的应用程序.vue
<script lang="ts">
import {Component, Vue} from 'vue-property-decorator';

@Component
class App extends Vue {}

export default App;
</script>

<template>
<div class="foobar">Babel worked</div>
</template>
我的构建脚本:
babel src/main.ts --out-dir build

最佳答案

不幸的是,您不能 构建 使用 babel,因为它只能转换语言并且不能构建模块。您仍然需要某种类型的捆绑程序来解决 require / import进口。如果你不想要庞大的 webpack 配置,你可以查看 RollupParcel
如果你想真正编译你 typescriptvue typescript你需要安装@babel/preset-typescript @babel/preset-env , 将它们包含在 .babelrc 中文件。
然后使用 babel ./src/main.ts --out-dir build --extensions ".ts"或者更好的是使用本地安装的 babel ./node_modules/.bin/babel ./src/main.ts --out-dir build --extensions ".ts"

关于javascript - 仅使用 babel 构建 typescript vue 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63577664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com