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

Add option for specifying multiple entry points #55

Merged
merged 2 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.2.1
8.9.3
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Pass in options as the second argument to `webpack`:

```javascript
const webpack = require('@cypress/webpack-preprocessor')

module.exports = (on) => {
const options = {
// send in the options from your webpack.config.js, so it works the same
Expand Down Expand Up @@ -93,6 +94,29 @@ Object of options for watching. See [webpack's docs](https://webpack.github.io/d

**Default**: `{}`

### additionalEntries

An array of file path strings for additional entries to be included in the bundle.

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.

**Default**: `[]`

**Example**:

```javascript
const webpack = require('@cypress/webpack-preprocessor')

module.exports = (on) => {
const options = {
webpackOptions: require('../../webpack.config'),
additionalEntries: ['./app/some-module.js'],
}

on('file:preprocessor', webpack(options))
}
```

## Modifying default options

The default options are provided as `webpack.defaultOptions` so they can be more easily modified.
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,15 @@ const preprocessor = (options = {}) => {
debug('webpackOptions: %o', webpackOptions)
debug('watchOptions: %o', watchOptions)

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

// we need to set entry and output
webpackOptions = Object.assign(webpackOptions, {
entry: filePath,
entry,
output: {
path: path.dirname(outputPath),
filename: path.basename(outputPath),
Expand Down
14 changes: 13 additions & 1 deletion test/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,19 @@ describe('webpack preprocessor', function () {

it('specifies the entry file', function () {
return this.run().then(() => {
expect(webpack.lastCall.args[0].entry).to.equal(this.file.filePath)
expect(webpack.lastCall.args[0].entry).to.eql([this.file.filePath])
})
})

it('includes additional entry files', function () {
return this.run({
additionalEntries: ['entry-1.js', 'entry-2.js'],
}).then(() => {
expect(webpack.lastCall.args[0].entry).to.eql([
this.file.filePath,
'entry-1.js',
'entry-2.js',
])
})
})

Expand Down