Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to auto import unplugin-icons ? #333

Open
5 tasks
yzhengwei opened this issue Dec 6, 2023 · 1 comment
Open
5 tasks

How to auto import unplugin-icons ? #333

yzhengwei opened this issue Dec 6, 2023 · 1 comment

Comments

@yzhengwei
Copy link

yzhengwei commented Dec 6, 2023

Describe the bug

When I created a js project using vue-cli, I wanted to auto import elementplus and icons , but the project couldn't run after the import。
the package.json like this:

  "dependencies": {
    "@element-plus/icons-vue": "^2.3.1",
    "core-js": "^3.8.3",
    "element-plus": "^2.4.3",
    "vue": "^3.2.13",
    "vue-router": "^4.0.3",
    "vuex": "^4.0.0"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-plugin-router": "~5.0.0",
    "@vue/cli-plugin-vuex": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3",
    "sass": "^1.32.7",
    "sass-loader": "^12.0.0",
    "unplugin-auto-import": "^0.17.2",
    "unplugin-icons": "^0.18.1",
    "unplugin-vue-components": "^0.26.0"
  },

vue.config.js:

const { defineConfig } = require('@vue/cli-service')

const Components = require('unplugin-vue-components/webpack')
const {ElementPlusResolver} = require('unplugin-vue-components/resolvers')
const Icons = require('unplugin-icons/webpack')
const IconsResolver = require('unplugin-icons/resolver')

module.exports = defineConfig({
    transpileDependencies: true,
    lintOnSave: false,
    configureWebpack: {
        plugins: [
            // AutoImport({
            //     resolvers: [
            //         ElementPlusResolver(),
            //         IconsResolver({
            //             prefix: 'Icon',
            //         }),
            //     ],
            // }),
            Components({
                resolvers: [
                    IconsResolver({enabledCollections: ["ep"]}),
                    ElementPlusResolver(),
                ],
            }),
            Icons({autoInstall: true}),
        ],
    }

})

and this is the error:

% npm run serve                

> myfirst@0.1.0 serve
> vue-cli-service serve

 ERROR  TypeError: IconsResolver is not a function
TypeError: IconsResolver is not a function
    at Object.<anonymous> (/Users/shareit/Library/CloudStorage/OneDrive-个人/Work/web/myfirst/vue.config.js:23:21)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at exports.loadModule (/Users/shareit/Library/CloudStorage/OneDrive-个人/Work/web/myfirst/node_modules/@vue/cli-shared-utils/lib/module.js:86:14)
    at loadFileConfig (/Users/shareit/Library/CloudStorage/OneDrive-个人/Work/web/myfirst/node_modules/@vue/cli-service/lib/util/loadFileConfig.js:30:20)
    at Service.loadUserOptions (/Users/shareit/Library/CloudStorage/OneDrive-个人/Work/web/myfirst/node_modules/@vue/cli-service/lib/Service.js:339:44)

Reproduction

3

System Info

System:
    OS: macOS 14.1.1
    CPU: (8) arm64 Apple M1
    Memory: 116.70 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    npm: 9.8.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 119.0.6045.199
    Safari: 17.1

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@wjw020206
Copy link

You can try the following code

const { defineConfig } = require('@vue/cli-service')

module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  configureWebpack: {
    plugins: [
      require('unplugin-icons/webpack').default({
        compiler: 'vue3',
        autoInstall: true
      }),
      require('unplugin-vue-components/webpack').default({
        resolvers: [
          require('unplugin-icons/resolver').default({
            enabledCollections: ['ep']
          }),
          require('unplugin-vue-components/resolvers').ElementPlusResolver()
        ]
      })
    ]
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants