Vuejs 库 CLI v3 排除 [英] Vuejs Library CLI v3 Exclude

查看:31
本文介绍了Vuejs 库 CLI v3 排除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 vuejs CLI 版本 3,并在 package.json 中使用此目标构建我的库

I am using vuejs CLI version 3 and am building my library using this target in the package.json

vue-cli-service build --report-json --target lib --name components src/appup-components.js

这个库使用了很多其他的外部库,比如 bootstrap-vue、axios 和 handlebars 等等.

This library uses lot of other external libraries like bootstrap-vue, axios and handlebars to name a few.

我的测试程序使用 npm install 导入这个库.

My test program imports this library using npm install.

图书馆建设在建设过程中非常缓慢,大约需要 2 分钟.然后启动应用服务器又需要 20-30 秒.生产力受到打击.

The library building is painfully slow while building and it takes about 2 mins. Then starting the app server takes another 20-30 secs. The productivity takes a hit.

问题- 我们是否也可以排除我们在测试应用程序中导入的库.我尝试在

Questions - Can we exclude the libraries which we import in the test app as well. I have tried in adding to externals under

configureWebpack: {
        externals: {
         }
    }

但它不编译

  • 有没有办法在监视模式下继续编译库.--watch 不允许它编译.它在第一次之后停止编译.

推荐答案

configureWebpack 对象位于 vue.config.js 文件中.然后,在 NODE_ENV 上使用三元组,以便在您使用 npm run serve 启动应用程序时仍会注入依赖项.

The configureWebpack object goes in a vue.config.js file. Then, use a ternary on the NODE_ENV so the dependencies still get injected when you launch your application with npm run serve.

参见 https://cli.vuejs.org/guide/webpack.html.

const webpack = require("webpack");

function getProdExternals() {
  return {
    axios: "axios",
    lodash: "lodash",
    jquery: "jQuery",
    vue: "Vue"
  };
}

module.exports = {
  configureWebpack: {
    externals: process.env.NODE_ENV === 'production' ?
      getProdExternals() : {}
  }
}

这篇关于Vuejs 库 CLI v3 排除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆