sunniejs / vue-h5-template

:tada:vue搭建移动端开发,基于vue-cli4.0+webpack 4+vant ui + sass+ rem适配方案+axios封装,构建手机端模板脚手架
https://sunniejs.github.io/vue-h5-template/
MIT License
3.08k stars 874 forks source link

程序启动失败了 #86

Closed huangweikuna closed 1 year ago

huangweikuna commented 1 year ago
➜  vue-h5-template git:(vue-h5-template) yarn -v
1.22.18
➜  vue-h5-template git:(vue-h5-template) node -v
v14.19.2
➜  vue-h5-template git:(vue-h5-template) yarn install 
yarn install v1.22.18
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
[2/4] Fetching packages...
warning vite-plugin-progress@0.0.3: The engine "pnpm" appears to be invalid.
[3/4] Linking dependencies...
[4/4] Building fresh packages...

$ husky install
husky - Git hooks installed
Done in 4.10s.
➜  vue-h5-template git:(vue-h5-template) yarn dev    
yarn run v1.22.18
$ vite
                                                                                                                                                                                                                               09:42:44
  vite v2.9.14 dev server running at:

  > Local:    http://localhost:3000/                                                                                                                                                                                           09:42:44
  > Network:  http://172.26.48.66:3000/                                                                                                                                                                                        09:42:44
                                                                                                                                                                                                                               09:42:44
  ready in 703ms.

 ERROR  Failed to resolve import "@nutui/nutui/dist/packages/Button/index.scss" from "src/plugins/nutUI.ts". Does the file exist?                                                                                              09:42:46

 ERROR  9:42:46 AM [vite] Internal server error: Failed to resolve import "@nutui/nutui/dist/packages/Button/index.scss" from "src/plugins/nutUI.ts". Does the file exist?                                                     09:42:46
  Plugin: vite:import-analysis
  File: /work/vue/vue-h5-template/src/plugins/nutUI.ts
  33 |    GridItem
  34 |  } from "@nutui/nutui";
  35 |  import '@nutui/nutui/dist/packages/Button/index.scss';
     |          ^
  36 |  import '@nutui/nutui/dist/packages/Cell/index.scss';
  37 |  import '@nutui/nutui/dist/packages/CellGroup/index.scss';
      at formatError (/work/vue/vue-h5-template/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39080:46)
      at TransformContext.error (/work/vue/vue-h5-template/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39076:19)
      at normalizeUrl (/work/vue/vue-h5-template/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:58354:26)
      at processTicksAndRejections (internal/process/task_queues.js:95:5)
      at async TransformContext.transform (/work/vue/vue-h5-template/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:58503:57)
      at async Object.transform (/work/vue/vue-h5-template/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:39317:30)
      at async doTransform (/work/vue/vue-h5-template/node_modules/vite/dist/node/chunks/dep-c9998dc6.js:50037:29)
huangweikuna commented 1 year ago

在@fonghehe 大佬指导下,修改 config/vite/plugins/styleImport.ts 解决

/**
 * @name ConfigRestartPlugin
 * @description 按需引入样式文件
 */
import { createStyleImportPlugin, Lib, VantResolve } from 'vite-plugin-style-import';

function MyNutuiResolve(): Lib {
  return {
    libraryName: '@nutui/nutui',
    libraryNameChangeCase: 'pascalCase',
    resolveStyle: (name) => {
      return `@nutui/nutui/dist/packages/${name.toLowerCase()}/index.scss`;
    },
  };
}

export const ConfigStyleImport = () => {
  return createStyleImportPlugin({
    resolves: [MyNutuiResolve(), VantResolve()],
  });
};