|
1 |
| -import * as webpack from 'webpack' |
2 | 1 | import * as Promise from 'bluebird'
|
3 | 2 | import * as events from 'events'
|
4 |
| - |
| 3 | +import * as _ from 'lodash' |
| 4 | +import * as webpack from 'webpack' |
5 | 5 | import { createDeferred } from './deferred'
|
6 | 6 |
|
7 | 7 | const path = require('path')
|
@@ -122,40 +122,45 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
|
122 | 122 | return bundles[filePath]
|
123 | 123 | }
|
124 | 124 |
|
125 |
| - // user can override the default options |
126 |
| - let webpackOptions: webpack.Configuration = options.webpackOptions || getDefaultWebpackOptions() |
127 |
| - const watchOptions = options.watchOptions || {} |
| 125 | + const defaultWebpackOptions = getDefaultWebpackOptions() |
128 | 126 |
|
129 |
| - debug('webpackOptions: %o', webpackOptions) |
130 |
| - debug('watchOptions: %o', watchOptions) |
131 |
| - |
132 |
| - const entry = [filePath].concat(options.additionalEntries || []) |
133 | 127 | // we're provided a default output path that lives alongside Cypress's
|
134 | 128 | // app data files so we don't have to worry about where to put the bundled
|
135 | 129 | // file on disk
|
136 | 130 | const outputPath = path.extname(file.outputPath) === '.js'
|
137 | 131 | ? file.outputPath
|
138 | 132 | : `${file.outputPath}.js`
|
139 | 133 |
|
140 |
| - // we need to set entry and output |
141 |
| - webpackOptions = Object.assign(webpackOptions, { |
| 134 | + const entry = [filePath].concat(options.additionalEntries || []) |
| 135 | + |
| 136 | + const watchOptions = options.watchOptions || {} |
| 137 | + |
| 138 | + // user can override the default options |
| 139 | + const webpackOptions: webpack.Configuration = _ |
| 140 | + .chain(options.webpackOptions) |
| 141 | + .defaultTo(defaultWebpackOptions) |
| 142 | + .defaults({ |
| 143 | + mode: defaultWebpackOptions.mode, |
| 144 | + }) |
| 145 | + .assign({ |
| 146 | + // we need to set entry and output |
142 | 147 | entry,
|
143 | 148 | output: {
|
144 | 149 | path: path.dirname(outputPath),
|
145 | 150 | filename: path.basename(outputPath),
|
146 | 151 | },
|
147 | 152 | })
|
| 153 | + .tap((opts) => { |
| 154 | + if (opts.devtool !== false) { |
| 155 | + debug('setting devtool to inline-source-map') |
148 | 156 |
|
149 |
| - if (webpackOptions.devtool !== false) { |
150 |
| - debug('setting devtool to inline-source-map') |
151 |
| - webpackOptions.devtool = 'inline-source-map' |
152 |
| - } |
153 |
| - |
154 |
| - if (!('mode' in webpackOptions)) { |
155 |
| - debug('setting webpack mode to development') |
156 |
| - webpackOptions.mode = 'development' |
157 |
| - } |
| 157 | + opts.devtool = 'inline-source-map' |
| 158 | + } |
| 159 | + }) |
| 160 | + .value() as any |
158 | 161 |
|
| 162 | + debug('webpackOptions: %o', webpackOptions) |
| 163 | + debug('watchOptions: %o', watchOptions) |
159 | 164 | debug(`input: ${filePath}`)
|
160 | 165 | debug(`output: ${outputPath}`)
|
161 | 166 |
|
@@ -282,8 +287,7 @@ const preprocessor: WebpackPreprocessor = (options: PreprocessorOptions = {}): F
|
282 | 287 | }
|
283 | 288 | }
|
284 | 289 |
|
285 |
| -// provide a clone of the default options, lazy-loading them |
286 |
| -// so they aren't required unless the user utilizes them |
| 290 | +// provide a clone of the default options |
287 | 291 | Object.defineProperty(preprocessor, 'defaultOptions', {
|
288 | 292 | get () {
|
289 | 293 | debug('get default options')
|
|
0 commit comments