fix(build): avoid default import warning when lib entry has no default export

close #1641
This commit is contained in:
Evan You
2018-07-17 12:44:25 -04:00
parent 369f97238e
commit d26cb864b4
2 changed files with 17 additions and 3 deletions
@@ -0,0 +1,2 @@
import './setPublicPath'
export * from '~entry'
@@ -12,7 +12,9 @@ module.exports = (api, { entry, name }, options) => {
process.exit(1)
}
if (!fs.existsSync(api.resolve(entry))) {
const fullEntryPath = api.resolve(entry)
if (!fs.existsSync(fullEntryPath)) {
abort(
`Failed to resolve lib entry: ${entry}${entry === `src/App.vue` ? ' (default)' : ''}. ` +
`Make sure to specify the correct entry file.`
@@ -71,13 +73,23 @@ module.exports = (api, { entry, name }, options) => {
const entryName = `${libName}.${postfix}`
config.resolve
.alias
.set('~entry', api.resolve(entry))
.set('~entry', fullEntryPath)
// set entry/output after user configureWebpack hooks are applied
const rawConfig = api.resolveWebpackConfig(config)
let realEntry = require.resolve('./entry-lib.js')
// avoid importing default if user entry file does not have default export
if (!isVueEntry) {
const entryContent = fs.readFileSync(fullEntryPath, 'utf-8')
if (!/\b(export\s+default|export\s{[^}]+as\s+default)\b/.test(entryContent)) {
realEntry = require.resolve('./entry-lib-no-default.js')
}
}
rawConfig.entry = {
[entryName]: require.resolve('./entry-lib.js')
[entryName]: realEntry
}
rawConfig.output = Object.assign({