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 component
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
.
See 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() : {}
}
}