UNPKG

zoro-cli

Version:

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

46 lines (36 loc) 1.42 kB
// const { error } = require('zoro-cli-util/logger') module.exports = ({ configurator, options }) => { function genConfig(format, _options = {}) { const { postfix, min } = _options const webpackConfig = configurator.resolveChainableWebpackConfig() const entries = webpackConfig.entryPoints.entries() let entryName = Object.keys(entries)[0] const entryPath = webpackConfig.entry(entryName).values()[0] // entry entryName = postfix ? `${entryName}.${postfix}` : entryName webpackConfig.entryPoints.clear() webpackConfig.entry(entryName).add(entryPath) // output webpackConfig.output .libraryTarget(format) .filename(`${entryName}.js`) .chunkFilename(`${entryName}.[name].js`) // adjust css output name so they write to the same file if (webpackConfig.plugins.has('extract-css')) { webpackConfig.plugin('extract-css').tap(args => { args[0].filename = `${entryName}.css` return args }) } webpackConfig.optimization.minimize(min === true) const config = configurator.resolveWebpackConfig(webpackConfig) return config } const { filenamePostfixes = {} } = options const { common = 'common', umd = '', umdMin = 'min' } = filenamePostfixes return [ genConfig('commonjs2', { postfix: common }), genConfig('umd', { postfix: umd }), genConfig('umd', { postfix: umdMin, min: true }), ] }