Skip to content

Commit

Permalink
fix: support entry descriptor (closes #2453) (#2465)
Browse files Browse the repository at this point in the history
  • Loading branch information
smelukov committed Mar 18, 2020
1 parent 50c09a4 commit 8bbef6a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/utils/addEntries.js
Expand Up @@ -68,7 +68,14 @@ function addEntries(config, options, server) {

Object.keys(originalEntry).forEach((key) => {
// entry[key] should be a string here
clone[key] = prependEntry(originalEntry[key], additionalEntries);
const entryDescription = originalEntry[key];
if (typeof entryDescription === 'object' && entryDescription.import) {
clone[key] = Object.assign({}, entryDescription, {
import: prependEntry(entryDescription.import, additionalEntries),
});
} else {
clone[key] = prependEntry(entryDescription, additionalEntries);
}
});

return clone;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/entry-as-descriptor/foo.js
@@ -0,0 +1,3 @@
'use strict';

console.log('i am foo!');
24 changes: 24 additions & 0 deletions test/fixtures/entry-as-descriptor/webpack.config.js
@@ -0,0 +1,24 @@
'use strict';

module.exports = {
mode: 'development',
context: __dirname,
entry: {
main: {
import: './foo.js',
},
},
plugins: [
{
apply(compiler) {
compiler.hooks.done.tap('webpack-dev-server', (stats) => {
let exitCode = 0;
if (stats.hasErrors()) {
exitCode = 1;
}
setTimeout(() => process.exit(exitCode));
});
},
},
],
};
12 changes: 12 additions & 0 deletions test/server/utils/addEntries.test.js
Expand Up @@ -5,6 +5,7 @@ const webpack = require('webpack');
const addEntries = require('../../../lib/utils/addEntries');
const config = require('./../../fixtures/simple-config/webpack.config');
const configEntryAsFunction = require('./../../fixtures/entry-as-function/webpack.config');
const configEntryAsDescriptor = require('./../../fixtures/entry-as-descriptor/webpack.config');

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

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

it('should supports entry as descriptor', () => {
const webpackOptions = Object.assign({}, configEntryAsDescriptor);
const devServerOptions = {};

addEntries(webpackOptions, devServerOptions);

expect(typeof webpackOptions.entry === 'object').toBe(true);
expect(typeof webpackOptions.entry.main === 'object').toBe(true);
expect(Array.isArray(webpackOptions.entry.main.import)).toBe(true);
});

it('should only prepends devServer entry points to web targets by default', () => {
const webpackOptions = [
Object.assign({}, config),
Expand Down

0 comments on commit 8bbef6a

Please sign in to comment.