Skip to content

Commit

Permalink
fix: should resolve to full path when setting default entryFiles
Browse files Browse the repository at this point in the history
closes #3616
closes #3618
  • Loading branch information
haoqunjiang committed Mar 12, 2019
1 parent 29d7d0b commit dd37773
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
18 changes: 18 additions & 0 deletions packages/@vue/cli-service/__tests__/Service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ test('api: configureWebpack', () => {
}])

const config = service.resolveWebpackConfig()
console.log(process.env.VUE_CLI_ENTRY_FILES)
expect(config.output.path).toBe('test-dist-2')
})

Expand Down Expand Up @@ -296,6 +297,23 @@ test('api: configureWebpack preserve ruleNames', () => {
expect(config.module.rules[0].__ruleNames).toEqual(['js'])
})

test.only('internal: should correctly set VUE_CLI_ENTRY_FILES', () => {

This comment has been minimized.

Copy link
@BuptStEve

BuptStEve Mar 12, 2019

emmm, maybe delete the only?

This comment has been minimized.

Copy link
@haoqunjiang

haoqunjiang Mar 12, 2019

Author Member

Ah…… thanks for pointing out! 😂😂😂

const service = createMockService([{
id: 'test',
apply: api => {
api.configureWebpack(config => {
config.entry = {
page1: './src/page1.js',
page2: './src/page2.js'
}
})
}
}])

service.resolveWebpackConfig()
expect(process.env.VUE_CLI_ENTRY_FILES).toEqual('["/src/page1.js","/src/page2.js"]')
})

test('api: configureDevServer', () => {
const cb = () => {}
const service = createMockService([{
Expand Down
19 changes: 15 additions & 4 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,21 @@ module.exports = class Service {
)
}

const entryFiles = Object.values(config.entry || []).reduce((allEntries, curr) => {
return allEntries.concat(curr)
}, [])
process.env.VUE_CLI_ENTRY_FILES = JSON.stringify(entryFiles)
if (typeof config.entry !== 'function') {
let entryFiles
if (typeof config.entry === 'string') {
entryFiles = [config.entry]
} else if (Array.isArray(config.entry)) {
entryFiles = config.entry
} else {
entryFiles = Object.values(config.entry || []).reduce((allEntries, curr) => {
return allEntries.concat(curr)
}, [])
}

entryFiles = entryFiles.map(file => path.resolve(this.context, file))
process.env.VUE_CLI_ENTRY_FILES = JSON.stringify(entryFiles)
}

return config
}
Expand Down

0 comments on commit dd37773

Please sign in to comment.