-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e85052
commit 280d7c0
Showing
8 changed files
with
146 additions
and
34 deletions.
There are no files selected for viewing
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
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,13 @@ | ||
import getConfig from '../static/getConfig' | ||
import { webpackConfig } from '../static/webpack' | ||
|
||
// Required so handle static.config.js defined as es module | ||
require('../utils/binHelper') | ||
|
||
export default (function getWebpackConfig(configPath, stage = 'dev') { | ||
return new Promise(resolve => | ||
getConfig(configPath, staticConfig => | ||
resolve(webpackConfig({ config: staticConfig, stage })) | ||
) | ||
) | ||
}) |
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,10 @@ | ||
import getConfig from '../static/getConfig' | ||
import { webpackConfig } from '../static/webpack' | ||
|
||
// Required so handle static.config.js defined as es module | ||
require('../utils/binHelper') | ||
|
||
export default (function getWebpackConfigSync(configPath, stage = 'dev') { | ||
const staticConfig = getConfig(configPath, undefined, { sync: true }) | ||
return webpackConfig({ config: staticConfig, stage, sync: true }) | ||
}) |
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
54 changes: 54 additions & 0 deletions
54
packages/react-static/src/static/__tests__/webpack.test.js
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,54 @@ | ||
import { webpackConfig } from '../webpack' | ||
import staticConfig from '../__mocks__/defaultConfigDevelopment.mock' | ||
|
||
const createConfigWithWebpackHook = hook => { | ||
const hooks = { webpack: hook } | ||
return Object.assign({}, staticConfig, { plugins: [{ hooks }] }) | ||
} | ||
|
||
describe('webpack', () => { | ||
describe('when called synchronously', () => { | ||
it('should return after executing plugin hooks sync', () => { | ||
const config = createConfigWithWebpackHook(wpConfig => | ||
Object.assign(wpConfig, { mode: 'development' }) | ||
) | ||
|
||
const myWebpackConfig = webpackConfig({ | ||
config, | ||
stage: 'prod', | ||
sync: true, | ||
}) | ||
|
||
expect(myWebpackConfig.mode).toBe('development') | ||
}) | ||
|
||
it('should throw if plugin hooks execute async', () => { | ||
const config = createConfigWithWebpackHook(wpConfig => | ||
Promise.resolve(Object.assign(wpConfig, { mode: 'development' })) | ||
) | ||
|
||
expect(() => | ||
webpackConfig({ | ||
config, | ||
stage: 'prod', | ||
sync: true, | ||
}) | ||
).toThrow('Cannot run async hooks in sync mode') | ||
}) | ||
}) | ||
|
||
describe('when called asynchronously', () => { | ||
it('should resolve after executing plugin hooks async', async () => { | ||
const config = createConfigWithWebpackHook(wpConfig => | ||
Promise.resolve(Object.assign(wpConfig, { mode: 'development' })) | ||
) | ||
|
||
const myWebpackConfig = await webpackConfig({ | ||
config, | ||
stage: 'prod', | ||
}) | ||
|
||
expect(myWebpackConfig.mode).toBe('development') | ||
}) | ||
}) | ||
}) |
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