UNPKG

zoro-cli

Version:

https://github.com/vuejs/vue-cli

43 lines (35 loc) 1.03 kB
const fs = require('fs') const path = require('path') const { error } = require('zoro-cli-util/logger') module.exports = ({ api, options, pkg }) => { if (options.target !== 'lib') return api.chainWebpack(webpackConfig => { const { entry } = options const fullEntryPath = api.resolve(entry) // check entry existence if (!entry || !fs.existsSync(fullEntryPath)) { error(`找不到 entry: ${entry}`) process.exit(-1) } // config entry webpackConfig.entryPoints.clear() webpackConfig .entry(options.entryName || pkg.name) .add(fullEntryPath) .end() // user may override the libName by project.config.js -> libName const libName = options.libName || pkg.libName || path.basename(entry).replace(/\..*$/, '') webpackConfig.output.library(libName) // externalize Vue in case user imports it webpackConfig.externals({ vue: { commonjs: 'vue', commonjs2: 'vue', root: 'Vue', }, }) }) }