Skip to content
This repository was archived by the owner on Oct 1, 2020. It is now read-only.

Commit b7414c3

Browse files
committed
minor: add option to specify additional entries
1 parent 0e5914c commit b7414c3

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Pass in options as the second argument to `webpack`:
4848

4949
```javascript
5050
const webpack = require('@cypress/webpack-preprocessor')
51+
5152
module.exports = (on) => {
5253
const options = {
5354
// send in the options from your webpack.config.js, so it works the same
@@ -93,6 +94,29 @@ Object of options for watching. See [webpack's docs](https://webpack.github.io/d
9394

9495
**Default**: `{}`
9596

97+
### additionalEntries
98+
99+
An array of file path strings for additional entries to be included in the bundle.
100+
101+
By necessity, this preprocessor sets the entry point for webpack as the spec file or support file. The `additionalEntries` option allows you to specify more entry points in order to utilize webpack's [multi-main entry](https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax). This allows runtime dependency resolution.
102+
103+
**Default**: `[]`
104+
105+
**Example**:
106+
107+
```javascript
108+
const webpack = require('@cypress/webpack-preprocessor')
109+
110+
module.exports = (on) => {
111+
const options = {
112+
webpackOptions: require('../../webpack.config'),
113+
additionalEntries: ['./app/some-module.js'],
114+
}
115+
116+
on('file:preprocessor', webpack(options))
117+
}
118+
```
119+
96120
## Modifying default options
97121

98122
The default options are provided as `webpack.defaultOptions` so they can be more easily modified.

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ const preprocessor = (options = {}) => {
7272
debug('webpackOptions: %o', webpackOptions)
7373
debug('watchOptions: %o', watchOptions)
7474

75+
const entry = [filePath].concat(options.additionalEntries || [])
7576
// we're provided a default output path that lives alongside Cypress's
7677
// app data files so we don't have to worry about where to put the bundled
7778
// file on disk
7879
const outputPath = file.outputPath
7980

8081
// we need to set entry and output
8182
webpackOptions = Object.assign(webpackOptions, {
82-
entry: filePath,
83+
entry,
8384
output: {
8485
path: path.dirname(outputPath),
8586
filename: path.basename(outputPath),

test/index_spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,19 @@ describe('webpack preprocessor', function () {
9898

9999
it('specifies the entry file', function () {
100100
return this.run().then(() => {
101-
expect(webpack.lastCall.args[0].entry).to.equal(this.file.filePath)
101+
expect(webpack.lastCall.args[0].entry).to.eql([this.file.filePath])
102+
})
103+
})
104+
105+
it('includes additional entry files', function () {
106+
return this.run({
107+
additionalEntries: ['entry-1.js', 'entry-2.js'],
108+
}).then(() => {
109+
expect(webpack.lastCall.args[0].entry).to.eql([
110+
this.file.filePath,
111+
'entry-1.js',
112+
'entry-2.js',
113+
])
102114
})
103115
})
104116

0 commit comments

Comments
 (0)