李恒道 发表于 2022-3-19 21:57:05

vue-loader安装@vue/compile-sfc模块问题

在早期vue配置webpack的过程中安装vue-loader之后需要安装对应的sfc模块

但是在vue3一定版本之后不再需要了

在https://github.com/vuejs/core/tree/main/packages

可以看到存在compile-sfc

然后安装vue-loader

在dist的compiler.js部分可以看到

```
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compiler = void 0;
try {
    // Vue 3.2.13+ ships the SFC compiler directly under the `vue` package
    // making it no longer necessary to have @vue/compiler-sfc separately installed.
    exports.compiler = require('vue/compiler-sfc');
}
catch (e) {
    try {
      exports.compiler = require('@vue/compiler-sfc');
    }
    catch (e) {
      throw new Error(`@vitejs/plugin-vue requires vue (>=3.2.13) or @vue/compiler-sfc ` +
            `to be present in the dependency tree.`);
    }
}

```

在Vue3.2.13+以上SFC编译直接在vue的package下

不再需要独立安装@vue/compiler-sfc模块了

也就是说我们安装vue后直接安装vue-loader然后配置webpack即可

无需安装sfc库

# 结语

发现这个问题的时候一脸懵逼...

心思为啥vue库有sfc模块还要再安sfc模块

结果尝试之后才发现市面上一堆文章都瞎抄...

根本不需要重复安装

都是抄来抄去一个模子

真烦人
页: [1]
查看完整版本: vue-loader安装@vue/compile-sfc模块问题