vite+vue3搭建

223 阅读1分钟
  1. 路径替换.

npm install --save-dev @types/node

import { resolve } from 'path'

const pathResolve = (dir: string): any => {
  return resolve(__dirname, ".", dir)
}

const alias: Record<string, string> = {
  '@': pathResolve('src')
}

export default defineConfig({
  plugins: [
    vue()
  ],
  resolve: { 
    alias
  }

})
  1. ts报错:Cannot find module '@/router' or its corresponding type declarations.ts(2307)

image.png resolution: image.png

declare module '*.type' {
    import { DefineComponent } from "vue"
    const component: DefineComponent<{}, {}, any>
    export default component
}

这个办法没什么用,对于{module} 导出会有ts2614的报错, 最后把vetur插件disable掉换成volar实现正常

  1. 安装jquery

import inject from "@rollup/plugin-inject"

  plugins: [
    vue(),
    inject({
      $: "jquery", // 这里会自动载入 node_modules 中的 jquery jquery全局变量
      jQuery: "jquery",
      "windows.jQuery": "jquery"
    })
  ],
@for $i from 1 through 30 {
  .p-#{$i} {
    padding: #{$i}+'px';
  }
}
  1. optimize image.png

  2. Property 'replaceAll' does not exist on type 'string'. Do you need to change your target library?

image.png

  1. px2rem+zoom 实现自适应

image.png

因为zoom属性的non-standard,所以在编译时会报错,改成

image.png 即可