DEV Community

Alan Castro
Alan Castro

Posted on • Edited on

Setup Vue3 with Ant Design

Ant design is my favorite design system and they already have a version that works with Vue3.

I'd like to share how to setup a Vue3 project with Ant Design using vue-cli.

Create a project with vue-cli

vue create your-app-name
Enter fullscreen mode Exit fullscreen mode

And then select Vue 3 option.

Install Vue Ant Design and some dependencies

cd create your-app-name
npm install ant-design-vue@next @ant-design/icons-vue
npm install -D less less-loader babel-plugin-import
Enter fullscreen mode Exit fullscreen mode

Create a vue.config.js file

module.exports = {
  css: {
    loaderOptions: {
      less: {
        lessOptions: {
          javascriptEnabled: true,
        },
      },
    },
  },
};
Enter fullscreen mode Exit fullscreen mode

Edit the babel.config.js file

module.exports = {
  presets: ['@vue/cli-plugin-babel/preset'],
  plugins: [
    [
      'import',
      { libraryName: 'ant-design-vue', libraryDirectory: 'es', style: true },
    ],
  ],
};
Enter fullscreen mode Exit fullscreen mode

Now you can import ant designs components on main.js like the following.

import { createApp } from 'vue'
import {
  Layout,
  Button,
  Spin,
  Result,
  Card,
  Divider,
  Col,
  Row,
  Drawer,
  Table,
  Form,
  InputNumber,
  Tag,
} from 'ant-design-vue';
import App from './App.vue'

const app = createApp(App);
app.config.productionTip = false;
app.use(Layout);
app.use(Button);
app.use(Spin);
app.use(Result);
app.use(Card);
app.use(Divider);
app.use(Col);
app.use(Row);
app.use(Drawer);
app.use(Table);
app.use(Form);
app.use(InputNumber);
app.use(Tag);
app.mount('#app');
Enter fullscreen mode Exit fullscreen mode

Check out my repository with this configuration done: https://github.com/alandecastros/vue3-ant-design-starter

See all the components that Ant Design offers at https://2x.antdv.com/docs/vue/introduce/.

That's it!

Top comments (6)

Collapse
 
noprod profile image
NOPR9D ☄️ • Edited

Nice !

chainWebpack equivalent :

module.exports = {
  chainWebpack: (config) => {
  config.module
      .rule("less")
      .use("less-loader")
      .loader("less-loader")
      .options({ javascriptEnabled: true })
      .end();
},
};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
thomas_sweet profile image
Thomas Sweet

Thank you for this!

Collapse
 
lltorres1983 profile image
Léo Torres

npm install ant-design-vue@next update to the last version of antd?

Collapse
 
valentinesean22 profile image
Valentine Sean Chanengeta

I am experiencing the error on the image, anyone to help?

Collapse
 
volchenokib profile image
Igor Volchenok • Edited

Cool!
Can I use sass instead of less?

Collapse
 
alandecastros profile image
Alan Castro

Yes, but I never did it.