Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support entry descriptor (closes #2453) #2465

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/utils/addEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ 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] = {
...entryDescription,
smelukov marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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