vue.config.js排除node_modules
时间: 2023-10-28 13:58:22 浏览: 405
可以通过在vue.config.js文件中添加以下内容来排除node_modules路径:
module.exports = {
transpileDependencies: [
'packageName',
],
chainWebpack: (config) => {
config.resolve.alias.set('node_modules', false);
},
};
这样配置后,webpack将不会打包node_modules路径下的文件。
相关问题
ERROR Error loading D:\htmlWorkplace\web59\vue.config.js: ERROR Error: Cannot find module 'webpack' Require stack: - D:\htmlWorkplace\web59\vue.config.js - D:\htmlWorkplace\web59\node_modules\.store\@vue+cli-shared-utils@4.5.19\node_modules\@vue\cli-shared-utils\lib\module.js - D:\htmlWorkplace\web59\node_modules\.store\@vue+cli-shared-utils@4.5.19\node_modules\@vue\cli-shared-utils\index.js - D:\htmlWorkplace\web59\node_modules\.store\@vue+cli-service@4.5.19\node_modules\@vue\cli-service\bin\vue-cli-service.js Error: Cannot find module 'webpack' Require stack: - D:\htmlWorkplace\web59\vue.config.js - D:\htmlWorkplace\web59\node_modules\.store\@vue+cli-shared-utils@4.5.19\node_modules\@vue\cli-shared-utils\lib\module.js - D:\htmlWorkplace\web59\node_modules\.store\@vue+cli-shared-utils@4.5.19\node_modules\@vue\cli-shared-utils\index.js - D:\htmlWorkplace\web59\node_modules\.store\@vue+cli-service@4.5.19\node_modules\@vue\cli-service\bin\vue-cli-service.js at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (D:\htmlWorkplace\web59\vue.config.js:2:17) at Module._compile (node:internal/modules/cjs/loader:1105:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10) at Module.load (node:internal/modules/cjs/loader:981:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Module.require (node:internal/modules/cjs/loader:1005:19)
这是一个错误信息,提示在加载 D:\htmlWorkplace\web59\vue.config.js 文件时出现了问题。错误的原因是找不到模块 'webpack',它是一个必需的模块。你需要先安装 webpack 模块,然后再尝试运行程序。你可以使用 npm install webpack 命令来安装 webpack 模块。
WARN "css.modules" option in vue.config.js is deprecated now, please use "css.requireModuleExtension" instead. INFO Starting development server... 98% after emitting CopyPlugin WARNING Compiled with 17 warnings 09:43:57 warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'computed' was not found in 'vue' warning in ./src/router/index.js "export 'default' (imported as 'VueRouter') was not found in 'vue-router' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'defineComponent' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'getCurrentInstance' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'h' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'inject' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'nextTick' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onActivated' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onDeactivated' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'onUnmounted' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'provide' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'reactive' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'ref' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'shallowRef' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'unref' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'watch' was not found in 'vue' warning in ./node_modules/vue-router/dist/vue-router.mjs "export 'watchEffect' was not found in 'vue'这个报错因为什么
这个报错是因为在使用Vue Router时,导入的Vue Router版本与当前项目中的Vue版本不匹配导致的。具体来说,Vue Router中使用了Vue 3的语法而当前项目中使用的是Vue 2,所以会出现一些语法上的错误。解决方法是将Vue Router更新到与当前项目中使用的Vue版本相匹配的版本。
阅读全文