Skip to content

Changing to support the "server" options object for webpack-dev-server #1125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
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
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,9 +709,12 @@ class Encore {
* ```
* Encore.configureDevServerOptions(function(options) {
* // change the configuration
* options.https = {
* key: '<your SSL cert key content>',
* cert: '<your SSL cert content>',
* options.server = {
* type: 'https',
* options: {
* key: '<your SSL cert key content or path>',
* cert: '<your SSL cert content or path>',
* }
* };
* });
* ```
Expand Down
16 changes: 13 additions & 3 deletions lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,22 @@ class ConfigGenerator {
/*
* An unfortunate situation where we need to configure the final runtime
* config later in the process. The problem is that devServer https can
* be activated with either a --https flag or by setting the devServer.https
* config to an object or true. So, only at this moment can we determine
* be activated with either a --server-type=https flag or by setting the devServer.server.type='https'
* config to true. So, only at this moment can we determine
* if https has been activated by either method.
*/
if (this.webpackConfig.useDevServer() && (devServerConfig.https || this.webpackConfig.runtimeConfig.devServerHttps)) {
if (this.webpackConfig.useDevServer() &&
(
devServerConfig.https
|| (devServerConfig.server && devServerConfig.server.type === 'https')
|| this.webpackConfig.runtimeConfig.devServerHttps
)) {
this.webpackConfig.runtimeConfig.devServerFinalIsHttps = true;

if (devServerConfig.https) {
logger.deprecation('The "https" option inside of configureDevServerOptions() is deprecated. Use "server = { type: \'https\' }" instead.');
}

} else {
this.webpackConfig.runtimeConfig.devServerFinalIsHttps = false;
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@babel/preset-env": "^7.16.0",
"@nuxt/friendly-errors-webpack-plugin": "^2.5.1",
"assets-webpack-plugin": "7.0.*",
"babel-loader": "^8.2.2",
"babel-loader": "^8.2.5",
"chalk": "^4.0.0",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^6.7.0",
Expand All @@ -55,7 +55,7 @@
"devDependencies": {
"@babel/eslint-parser": "^7.17.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.12.11",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.0.0",
"@hotwired/stimulus": "^3.0.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"less": "^4.0.0",
"less-loader": "^10.0.0",
"mocha": "^9.1.4",
"postcss": "^8.1.0",
"postcss": "^8.3.0",
"postcss-loader": "^6.0.0",
"preact": "^10.5.0",
"preact-compat": "^3.17.0",
Expand Down
18 changes: 12 additions & 6 deletions test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,24 @@ describe('The config-generator function', () => {
config.setPublicPath('/');
config.addEntry('main', './main');
config.configureDevServerOptions(options => {
options.https = {
key: 'https.key',
cert: 'https.cert',
options.server = {
'type': 'https',
options: {
key: 'https.key',
cert: 'https.cert',
}
};
});

const actualConfig = configGenerator(config);

expect(actualConfig.devServer).to.containSubset({
https: {
key: 'https.key',
cert: 'https.cert',
server: {
type: 'https',
options: {
key: 'https.key',
cert: 'https.cert',
}
},
});

Expand Down
19 changes: 10 additions & 9 deletions test/functional.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('Functional tests using webpack', function() {
config.addEntry('main', './js/code_splitting');
config.addStyleEntry('font', './css/roboto_font.css');
config.addStyleEntry('bg', './css/background_image.scss');
config.setPublicPath('http://localhost:8090/assets');
config.setPublicPath('http://127.0.0.1:8090/assets');
config.enableSassLoader();
config.setManifestKeyPrefix('assets');

Expand All @@ -249,21 +249,21 @@ describe('Functional tests using webpack', function() {
// check that the publicPath is set correctly
webpackAssert.assertOutputFileContains(
'runtime.js',
'__webpack_require__.p = "http://localhost:8090/assets/";'
'__webpack_require__.p = "http://127.0.0.1:8090/assets/";'
);

webpackAssert.assertOutputFileContains(
'bg.css',
'http://localhost:8090/assets/images/symfony_logo.91beba37.png'
'http://127.0.0.1:8090/assets/images/symfony_logo.91beba37.png'
);
webpackAssert.assertOutputFileContains(
'font.css',
'http://localhost:8090/assets/fonts/Roboto.e1dcc0db.woff2'
'http://127.0.0.1:8090/assets/fonts/Roboto.e1dcc0db.woff2'
);
// manifest file has CDN in value
webpackAssert.assertManifestPath(
'assets/main.js',
'http://localhost:8090/assets/main.js'
'http://127.0.0.1:8090/assets/main.js'
);

testSetup.requestTestPage(
Expand Down Expand Up @@ -292,7 +292,8 @@ describe('Functional tests using webpack', function() {

it('The devServer config loads successfully', (done) => {
const config = createWebpackConfig('public/assets', 'dev-server', {
port: '8090'
port: '8090',
host: '127.0.0.1',
});
config.addEntry('main', './js/code_splitting');
config.addStyleEntry('font', './css/roboto_font.css');
Expand All @@ -304,17 +305,17 @@ describe('Functional tests using webpack', function() {
// check that the publicPath is set correctly
webpackAssert.assertOutputFileContains(
'runtime.js',
'__webpack_require__.p = "http://localhost:8090/assets/";'
'__webpack_require__.p = "http://127.0.0.1:8090/assets/";'
);

webpackAssert.assertOutputFileContains(
'bg.css',
'http://localhost:8090/assets/images/symfony_logo.91beba37.png'
'http://127.0.0.1:8090/assets/images/symfony_logo.91beba37.png'
);
// manifest file has CDN in value
webpackAssert.assertManifestPath(
'assets/main.js',
'http://localhost:8090/assets/main.js'
'http://127.0.0.1:8090/assets/main.js'
);

testSetup.requestTestPage(
Expand Down
Loading