-
-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate advanced group (#1863)
Co-authored-by: Anshuman Verma <anshu.av97@gmail.com>
- Loading branch information
Showing
6 changed files
with
71 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const resolveAdvanced = require('../lib/groups/resolveAdvanced'); | ||
|
||
const targetValues = ['web', 'webworker', 'node', 'async-node', 'node-webkit', 'electron-main', 'electron-renderer', 'electron-preload']; | ||
|
||
describe('advanced options', function () { | ||
it('should load the HMR plugin', () => { | ||
const result = resolveAdvanced({ | ||
hot: true, | ||
}); | ||
expect(result.options.plugins[0].constructor.name).toEqual('HotModuleReplacementPlugin'); | ||
}); | ||
|
||
it('should load the prefetch plugin', () => { | ||
const result = resolveAdvanced({ | ||
prefetch: 'url', | ||
}); | ||
expect(result.options.plugins[0].constructor.name).toEqual('PrefetchPlugin'); | ||
}); | ||
|
||
{ | ||
targetValues.map((option) => { | ||
it(`should handle ${option} option`, () => { | ||
const result = resolveAdvanced({ | ||
target: option, | ||
}); | ||
expect(result.options.target).toEqual(option); | ||
}); | ||
}); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Resolve advanced flags | ||
* @param {args} args - Parsed args passed to CLI | ||
*/ | ||
const resolveAdvanced = (args) => { | ||
const { target, prefetch, hot } = args; | ||
|
||
const finalOptions = { | ||
options: {}, | ||
outputOptions: {}, | ||
}; | ||
|
||
if (hot) { | ||
const { HotModuleReplacementPlugin } = require('webpack'); | ||
const hotModuleVal = new HotModuleReplacementPlugin(); | ||
if (finalOptions.options && finalOptions.options.plugins) { | ||
finalOptions.options.plugins.unshift(hotModuleVal); | ||
} else { | ||
finalOptions.options.plugins = [hotModuleVal]; | ||
} | ||
} | ||
if (prefetch) { | ||
const { PrefetchPlugin } = require('webpack'); | ||
const prefetchVal = new PrefetchPlugin(null, args.prefetch); | ||
if (finalOptions.options && finalOptions.options.plugins) { | ||
finalOptions.options.plugins.unshift(prefetchVal); | ||
} else { | ||
finalOptions.options.plugins = [prefetchVal]; | ||
} | ||
} | ||
if (target) { | ||
finalOptions.options.target = args.target; | ||
} | ||
|
||
return finalOptions; | ||
}; | ||
|
||
module.exports = resolveAdvanced; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters