Skip to content

Commit dd37773

Browse files
committedMar 12, 2019
fix: should resolve to full path when setting default entryFiles
closes #3616 closes #3618
1 parent 29d7d0b commit dd37773

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed
 

‎packages/@vue/cli-service/__tests__/Service.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ test('api: configureWebpack', () => {
253253
}])
254254

255255
const config = service.resolveWebpackConfig()
256+
console.log(process.env.VUE_CLI_ENTRY_FILES)
256257
expect(config.output.path).toBe('test-dist-2')
257258
})
258259

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

300+
test.only('internal: should correctly set VUE_CLI_ENTRY_FILES', () => {
Has comments. Original line has comments.
301+
const service = createMockService([{
302+
id: 'test',
303+
apply: api => {
304+
api.configureWebpack(config => {
305+
config.entry = {
306+
page1: './src/page1.js',
307+
page2: './src/page2.js'
308+
}
309+
})
310+
}
311+
}])
312+
313+
service.resolveWebpackConfig()
314+
expect(process.env.VUE_CLI_ENTRY_FILES).toEqual('["/src/page1.js","/src/page2.js"]')
315+
})
316+
299317
test('api: configureDevServer', () => {
300318
const cb = () => {}
301319
const service = createMockService([{

‎packages/@vue/cli-service/lib/Service.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,21 @@ module.exports = class Service {
270270
)
271271
}
272272

273-
const entryFiles = Object.values(config.entry || []).reduce((allEntries, curr) => {
274-
return allEntries.concat(curr)
275-
}, [])
276-
process.env.VUE_CLI_ENTRY_FILES = JSON.stringify(entryFiles)
273+
if (typeof config.entry !== 'function') {
274+
let entryFiles
275+
if (typeof config.entry === 'string') {
276+
entryFiles = [config.entry]
277+
} else if (Array.isArray(config.entry)) {
278+
entryFiles = config.entry
279+
} else {
280+
entryFiles = Object.values(config.entry || []).reduce((allEntries, curr) => {
281+
return allEntries.concat(curr)
282+
}, [])
283+
}
284+
285+
entryFiles = entryFiles.map(file => path.resolve(this.context, file))
286+
process.env.VUE_CLI_ENTRY_FILES = JSON.stringify(entryFiles)
287+
}
277288

278289
return config
279290
}

0 commit comments

Comments
 (0)
Please sign in to comment.