Skip to content

Commit 8bbef6a

Browse files
authoredMar 18, 2020
fix: support entry descriptor (closes #2453) (#2465)
1 parent 50c09a4 commit 8bbef6a

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed
 

‎lib/utils/addEntries.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,14 @@ function addEntries(config, options, server) {
6868

6969
Object.keys(originalEntry).forEach((key) => {
7070
// entry[key] should be a string here
71-
clone[key] = prependEntry(originalEntry[key], additionalEntries);
71+
const entryDescription = originalEntry[key];
72+
if (typeof entryDescription === 'object' && entryDescription.import) {
73+
clone[key] = Object.assign({}, entryDescription, {
74+
import: prependEntry(entryDescription.import, additionalEntries),
75+
});
76+
} else {
77+
clone[key] = prependEntry(entryDescription, additionalEntries);
78+
}
7279
});
7380

7481
return clone;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
console.log('i am foo!');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
module.exports = {
4+
mode: 'development',
5+
context: __dirname,
6+
entry: {
7+
main: {
8+
import: './foo.js',
9+
},
10+
},
11+
plugins: [
12+
{
13+
apply(compiler) {
14+
compiler.hooks.done.tap('webpack-dev-server', (stats) => {
15+
let exitCode = 0;
16+
if (stats.hasErrors()) {
17+
exitCode = 1;
18+
}
19+
setTimeout(() => process.exit(exitCode));
20+
});
21+
},
22+
},
23+
],
24+
};

‎test/server/utils/addEntries.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const webpack = require('webpack');
55
const addEntries = require('../../../lib/utils/addEntries');
66
const config = require('./../../fixtures/simple-config/webpack.config');
77
const configEntryAsFunction = require('./../../fixtures/entry-as-function/webpack.config');
8+
const configEntryAsDescriptor = require('./../../fixtures/entry-as-descriptor/webpack.config');
89

910
const normalize = (entry) => entry.split(path.sep).join('/');
1011

@@ -290,6 +291,17 @@ describe('addEntries util', () => {
290291
expect(typeof webpackOptions.entry === 'function').toBe(true);
291292
});
292293

294+
it('should supports entry as descriptor', () => {
295+
const webpackOptions = Object.assign({}, configEntryAsDescriptor);
296+
const devServerOptions = {};
297+
298+
addEntries(webpackOptions, devServerOptions);
299+
300+
expect(typeof webpackOptions.entry === 'object').toBe(true);
301+
expect(typeof webpackOptions.entry.main === 'object').toBe(true);
302+
expect(Array.isArray(webpackOptions.entry.main.import)).toBe(true);
303+
});
304+
293305
it('should only prepends devServer entry points to web targets by default', () => {
294306
const webpackOptions = [
295307
Object.assign({}, config),

0 commit comments

Comments
 (0)
Please sign in to comment.