使用@vue/cli4腳手架,從零開始搭建typescript版的UI庫html
官網地址:https://cli.vuejs.org/zh/guid...vue
npm install -g @vue/cli # OR yarn global add @vue/cli vue --version @vue/cli 4.5.13 #當前版本
# 建立項目totoro vue create totoro # 配置選項 Vue CLI v4.5.13 ? Please pick a preset: Manually select features ? Check the features needed for your project: Choose Vue version, Babel, TS, Router, CSS Pre-processors, Linter, Unit ? Choose a version of Vue.js that you want to start the project with 2.x ? Use class-style component syntax? Yes ? Use Babel alongside TypeScript (required for modern mode, auto-detected polyfills, transpiling JSX)? Yes ? Use history mode for router? (Requires proper server setup for index fallback in production) No ? Pick a CSS pre-processor (PostCSS, Autoprefixer and CSS Modules are supported by default): Sass/SCSS (with dart-sass) ? Pick a linter / formatter config: Prettier ? Pick additional lint features: Lint on save ? Pick a unit testing solution: Jest ? Where do you prefer placing config for Babel, ESLint, etc.? In dedicated config files ? Save this as a preset for future projects? Yes ? Save preset as: vuecl4_vue2_ts ? Pick the package manager to use when installing dependencies: Yarn
# vscode settings.json文件 "editor.codeActionsOnSave": { "source.fixAll.eslint": true }
# 項目根目錄新建vue.config.js配置文件 module.exports = { devServer: { open: true,// 啓動項目時自動打開瀏覽器 }, };
# vue.config.js // eslint-disable-next-line @typescript-eslint/no-var-requires const path = require("path"); module.exports = { devServer: { open: true, }, pages: { index: { // page 的入口 entry: "website/main.ts", // 模板來源 template: "public/index.html", // 在 dist/index.html 的輸出 filename: "index.html", // 當使用 title 選項時 }, }, configureWebpack: { resolve: { // 設置別名 alias: { "totoro-ui": path.join(__dirname, "./"), packages: path.join(__dirname, "./packages"), "@": path.join(__dirname, "./website"), main: path.join(__dirname, "./src"), }, }, }, // 擴展 webpack 配置,使 packages 加入編譯 chainWebpack: (config) => { config.module .rule("js") .include.add(path.resolve(__dirname, "packages")) .end() .use("babel") .loader("babel-loader") .tap((options) => { // 修改它的選項... return options; }); }, };