-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): move filename option from create config to api
- Loading branch information
1 parent
8738bd1
commit d0c07dd
Showing
7 changed files
with
162 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
function setFilename(compiler, options) { | ||
const firstWpOpt = compiler.compilers | ||
? compiler.compilers[0].options | ||
: compiler.options; | ||
|
||
if (!options.filename && firstWpOpt.output && firstWpOpt.output.filename) { | ||
options.filename = firstWpOpt.output.filename; | ||
} | ||
} | ||
|
||
module.exports = setFilename; |
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,49 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`setFilename existing devServer.filename, existing compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "devserver-bundle.js", | ||
} | ||
`; | ||
|
||
exports[`setFilename existing devServer.filename, no compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "devserver-bundle.js", | ||
} | ||
`; | ||
|
||
exports[`setFilename multi compiler, existing devServer.filename, existing compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "devserver-bundle.js", | ||
} | ||
`; | ||
|
||
exports[`setFilename multi compiler, existing devServer.filename, no compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "devserver-bundle.js", | ||
} | ||
`; | ||
|
||
exports[`setFilename multi compiler, no devServer.filename, existing compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "mybundle.js", | ||
} | ||
`; | ||
|
||
exports[`setFilename multi compiler, no devServer.filename, no compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "[name].js", | ||
} | ||
`; | ||
|
||
exports[`setFilename no devServer.filename, existing compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "mybundle.js", | ||
} | ||
`; | ||
|
||
exports[`setFilename no devServer.filename, no compiler filename should set correct options.filename 1`] = ` | ||
Object { | ||
"filename": "[name].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
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,97 @@ | ||
'use strict'; | ||
|
||
const webpack = require('webpack'); | ||
const setFilename = require('../../../lib/utils/setFilename'); | ||
|
||
describe('setFilename', () => { | ||
const cases = [ | ||
{ | ||
title: 'no devServer.filename, no compiler filename', | ||
webpackFilename: null, | ||
multiCompiler: false, | ||
options: {}, | ||
}, | ||
{ | ||
title: 'no devServer.filename, existing compiler filename', | ||
webpackFilename: 'mybundle.js', | ||
multiCompiler: false, | ||
options: {}, | ||
}, | ||
{ | ||
title: 'existing devServer.filename, no compiler filename', | ||
webpackFilename: null, | ||
multiCompiler: false, | ||
options: { | ||
filename: 'devserver-bundle.js', | ||
}, | ||
}, | ||
{ | ||
title: 'existing devServer.filename, existing compiler filename', | ||
webpackFilename: 'mybundle.js', | ||
multiCompiler: false, | ||
options: { | ||
filename: 'devserver-bundle.js', | ||
}, | ||
}, | ||
{ | ||
title: 'multi compiler, no devServer.filename, no compiler filename', | ||
webpackFilename: null, | ||
multiCompiler: true, | ||
options: {}, | ||
}, | ||
{ | ||
title: | ||
'multi compiler, no devServer.filename, existing compiler filename', | ||
webpackFilename: 'mybundle.js', | ||
multiCompiler: true, | ||
options: {}, | ||
}, | ||
{ | ||
title: | ||
'multi compiler, existing devServer.filename, no compiler filename', | ||
webpackFilename: null, | ||
multiCompiler: true, | ||
options: { | ||
filename: 'devserver-bundle.js', | ||
}, | ||
}, | ||
{ | ||
title: | ||
'multi compiler, existing devServer.filename, existing compiler filename', | ||
webpackFilename: 'mybundle.js', | ||
multiCompiler: true, | ||
options: { | ||
filename: 'devserver-bundle.js', | ||
}, | ||
}, | ||
]; | ||
|
||
cases.forEach((data) => { | ||
describe(data.title, () => { | ||
let compiler; | ||
beforeAll(() => { | ||
let webpackConfig; | ||
if (data.multiCompiler) { | ||
// eslint-disable-next-line global-require | ||
webpackConfig = require('../../fixtures/multi-compiler-config/webpack.config'); | ||
if (data.webpackFilename) { | ||
webpackConfig[0].output.filename = data.webpackFilename; | ||
} | ||
} else { | ||
// eslint-disable-next-line global-require | ||
webpackConfig = require('../../fixtures/simple-config/webpack.config'); | ||
if (data.webpackFilename) { | ||
webpackConfig.output.filename = data.webpackFilename; | ||
} | ||
} | ||
|
||
compiler = webpack(webpackConfig); | ||
}); | ||
|
||
it('should set correct options.filename', () => { | ||
setFilename(compiler, data.options); | ||
expect(data.options).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |