mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-22 20:38:55 -05:00
fix(build): avoid default import warning when lib entry has no default export
close #1641
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user