vue2 使用 tailwind css vscode 100%成功

环境

vue -V ---- @vue/cli 5.0.8

node -v ----- v16.15.0

npm -v ----- 6.14.18

环境不一样可能不会100%成功哦

创建项目

vue create tailwind

选择vue2

修改package.json

javascript 复制代码
"dependencies": {
    "@babel/eslint-parser": "^7.24.7",
    "core-js": "^3.6.5",
    "vue": "^2.6.14"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~4.5.19",
    "@vue/cli-plugin-eslint": "~4.5.19",
    "@vue/cli-service": "~4.5.19",
    "autoprefixer": "^9.8.8",
    "eslint": "^6.7.2",
    "eslint-plugin-vue": "^6.2.2",
    "postcss": "^7.0.39",
    "tailwindcss": "npm:@tailwindcss/postcss7-compat@^2.2.17",
    "vue-template-compiler": "^2.6.11"
  },

修改vue.config.js

javascript 复制代码
//vue.config.js 
module.exports = {
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
            require("tailwindcss"), 
            require("autoprefixer")
        ],
      },
    },
  },
};

根目录新增文件 .eslintrc.js

javascript 复制代码
module.exports = {
  root: true,
  env: {
    node: true,
    jquery: true
  },
  'extends': [
    'plugin:vue/essential',
    'eslint:recommended'
  ],
  parserOptions: {
    parser: '@babel/eslint-parser'
  },
  rules: {
    // allow async-await
    'generator-star-spacing': 'off',
    // allow debugger during development
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    // 禁止修改const声明的变量
    'no-const-assign': 2,
    // 缩进
    'indent': 0,
    //函数参数不能重复
    'no-dupe-args': 2,
    //switch中的case标签不能重复
    'no-duplicate-case': 2,
    //禁止非必要的括号
    'no-extra-parens': 2,
    //禁止多余的冒号
    'no-extra-semi': 2,
    //空行最多不能超过2行
    'no-multiple-empty-lines': [1, {'max': 2}],
    'no-tabs':'off',
    //'vue/script-indent': ['error', 2, {'baseIndent': 1}],
    //引号类型 `` "" ''
    'quotes': [2, 'single'],
    "camelcase": 0,
    'no-useless-escape':0,
    'no-array-constructor': 0,//禁止使用数组构造器
    'spaced-comment': ['error', 'always'],
    'no-multi-spaces': [0, {ignoreEOLComments: true}],
    'new-cap':0,
    "vue/no-parsing-error": [2, { "x-invalid-end-tag": false }],
    "eqeqeq": [2, "allow-null"],
    "no-dupe-keys": 2,//在创建对象字面量时不允许键重复 {a:1,a:1}
    "space-before-function-paren": [0, "always"],//函数定义时括号前面要不要有空格
    "no-var": 2,
    "no-unused-vars": 0,
    "vue/valid-v-model": 0
  }
}

修改src/main.js

javascript 复制代码
import Vue from 'vue'
import App from './App.vue'
import '@/assets/tailwindcss.css'
Vue.config.productionTip = false

new Vue({
  render: h => h(App),
}).$mount('#app')

在src/assets 里面新增文件tailwindcss.css

javascript 复制代码
@tailwind base;
@tailwind components;
@tailwind utilities;

在根目录新增文件tailwind.config.js

javascript 复制代码
/** @type {import('tailwindcss').Config} */
module.exports = {
  //文件路径根据自己项目来定,可能是 ./src/**/*.{js,ts,jsx,tsx}
  purge: ["./app/**/*.{js,jsx,vue}", "./app/index.html"],
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {}
  },
  variants: {},
  plugins: []
};

vscode按照插件Tailwind CSS IntelliSense

npm install rimraf -g

rimraf node_modules

npm install

npm install tailwindcss@npm:@tailwindcss/postcss7-compat @tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9

启动项目 npm run serve

相关推荐
木斯佳3 分钟前
前端八股文面经大全:26届秋招滴滴校招前端一面面经-事件循环题解析
前端·状态模式
光影少年23 分钟前
react状态管理都有哪些及优缺点和应用场景
前端·react.js·前端框架
saber_andlibert2 小时前
TCMalloc底层实现
java·前端·网络
逍遥德2 小时前
如何学编程之01.理论篇.如何通过阅读代码来提高自己的编程能力?
前端·后端·程序人生·重构·软件构建·代码规范
冻感糕人~2 小时前
【珍藏必备】ReAct框架实战指南:从零开始构建AI智能体,让大模型学会思考与行动
java·前端·人工智能·react.js·大模型·就业·大模型学习
程序员agions2 小时前
2026年,“配置工程师“终于死绝了
前端·程序人生
alice--小文子2 小时前
cursor-mcp工具使用
java·服务器·前端
晚霞的不甘2 小时前
揭秘 CANN 内存管理:如何让大模型在小设备上“轻装上阵”?
前端·数据库·经验分享·flutter·3d
小迷糊的学习记录2 小时前
0.1 + 0.2 不等于 0.3
前端·javascript·面试
梦帮科技3 小时前
Node.js配置生成器CLI工具开发实战
前端·人工智能·windows·前端框架·node.js·json