Vue 2 Vite 应用程序:无法解析源以进行导入分析
Vue 2 Vite app: Failed to parse source for import analysis
我目前正在使用 vite 设置一个 vue 2 应用程序。
我遇到了这个错误。我想在 vue 2 中设置项目。我知道它是为 vue 3 构建的,但是我缺少什么吗?
vite 配置
import { minifyHtml, injectHtml } from 'vite-plugin-html'
import legacy from '@vitejs/plugin-legacy'
const path = require('path')
const { createVuePlugin } = require('vite-plugin-vue2')
module.exports = {
plugins: [
createVuePlugin(),
minifyHtml(),
injectHtml({
injectData: {
title: 'ProjectName',
description: 'A single page application created using Vue.js'
}
}),
legacy({
targets: ['ie >= 11'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime']
})
],
resolve: {
alias: {
'@': path.resolve(__dirname, '/src'),
'~bootstrap': 'bootstrap'
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "./src/scss/variables";`
}
}
}
}
我的文件夹结构:
我的package.json
{
"name": "co",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^4.1.3",
"@vitejs/plugin-legacy": "^1.8.1",
"@vitejs/plugin-vue": "^1.6.1",
"autoprefixer": "^10.4.5",
"postcss": "^8.4.12",
"sass": "~1.32.13",
"vite": "^2.9.6",
"vite-plugin-vue2": "^1.9.0",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"bootstrap": "^4.6.0",
"eslint": "^8.14.0",
"eslint-plugin-vue": "^8.7.1",
"vue": "^2.6.11",
"vue-router": "^3.2.0"
}
}
使用以下内容更新了我的配置。似乎已经开始工作了!
import { defineConfig } from "vite";
import { createVuePlugin as vue } from "vite-plugin-vue2";
// https://vitejs.dev/config/const
const path = require("path");
export default defineConfig({
plugins: [vue()],
resolve: {
extensions: [
".mjs",
".js",
".ts",
".jsx",
".tsx",
".json",
".vue",
".scss",
],
alias: {
"@": path.resolve(__dirname, "./src"),
json2csv: "json2csv/dist/json2csv.umd.js",
'~bootstrap': 'bootstrap'
},
},
css: {
preprocessorOptions: {
scss: {
// additionalData: `@import "@/scss/app.scss";`,
additionalData: `@import "src/scss/_variables.scss";`,
},
},
},
server: {
port: 8090,
},
});
我目前正在使用 vite 设置一个 vue 2 应用程序。
我遇到了这个错误。我想在 vue 2 中设置项目。我知道它是为 vue 3 构建的,但是我缺少什么吗?
vite 配置
import { minifyHtml, injectHtml } from 'vite-plugin-html'
import legacy from '@vitejs/plugin-legacy'
const path = require('path')
const { createVuePlugin } = require('vite-plugin-vue2')
module.exports = {
plugins: [
createVuePlugin(),
minifyHtml(),
injectHtml({
injectData: {
title: 'ProjectName',
description: 'A single page application created using Vue.js'
}
}),
legacy({
targets: ['ie >= 11'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime']
})
],
resolve: {
alias: {
'@': path.resolve(__dirname, '/src'),
'~bootstrap': 'bootstrap'
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "./src/scss/variables";`
}
}
}
}
我的文件夹结构:
我的package.json
{
"name": "co",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"@fullhuman/postcss-purgecss": "^4.1.3",
"@vitejs/plugin-legacy": "^1.8.1",
"@vitejs/plugin-vue": "^1.6.1",
"autoprefixer": "^10.4.5",
"postcss": "^8.4.12",
"sass": "~1.32.13",
"vite": "^2.9.6",
"vite-plugin-vue2": "^1.9.0",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {
"bootstrap": "^4.6.0",
"eslint": "^8.14.0",
"eslint-plugin-vue": "^8.7.1",
"vue": "^2.6.11",
"vue-router": "^3.2.0"
}
}
使用以下内容更新了我的配置。似乎已经开始工作了!
import { defineConfig } from "vite";
import { createVuePlugin as vue } from "vite-plugin-vue2";
// https://vitejs.dev/config/const
const path = require("path");
export default defineConfig({
plugins: [vue()],
resolve: {
extensions: [
".mjs",
".js",
".ts",
".jsx",
".tsx",
".json",
".vue",
".scss",
],
alias: {
"@": path.resolve(__dirname, "./src"),
json2csv: "json2csv/dist/json2csv.umd.js",
'~bootstrap': 'bootstrap'
},
},
css: {
preprocessorOptions: {
scss: {
// additionalData: `@import "@/scss/app.scss";`,
additionalData: `@import "src/scss/_variables.scss";`,
},
},
},
server: {
port: 8090,
},
});