Skip to content

Instantly share code, notes, and snippets.

@Akryum
Created March 17, 2018 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akryum/53da1c59775cdb4beace2f6189b40205 to your computer and use it in GitHub Desktop.
Save Akryum/53da1c59775cdb4beace2f6189b40205 to your computer and use it in GitHub Desktop.
const { resolve } = require('path')
const chalk = require('chalk')
const findInFiles = require('find-in-files')
const importReg = /'(.*?)'$/
async function findVendorEntries (vendors, folder) {
const reg = `import (.*? from )?'((${vendors.join('|')})/.*?)'`
const results = await findInFiles.find(reg, folder, /\.(vue|jsx?|styl)$/)
const set = new Set(vendors)
for (const file in results) {
const result = results[file]
for (const n in result.matches) {
const matches = result.matches[n].match(importReg)
if (matches && matches.length > 1) {
const p = matches[1]
set.add(p)
}
}
}
return Array.from(set)
}
module.exports = {
getAlias,
formatModule,
findVendorEntries,
}
const { findVendorEntries } = require('./utils')
module.exports = {
plugins: [
new AutoDllPlugin({
path: resolve(__dirname, '../dist/'),
filename: '[name].dll.js',
entry: {
vendor: [
...await findVendorEntries(Object.keys(packageData.dependencies), resolve(__dirname, '../src/')),
'core-js',
'common/css/vendors',
'common/js/vendors',
],
},
context,
debug: true,
inherit: true,
}),
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment