File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,24 @@ export default {
3232
3333Then visit the https URL of the page, and confirm in your browser.
3434
35+ ## Options
36+
37+ If you need to customize the compilation behavior of Sass, you can use the following configs.
38+
39+ ### filename
40+
41+ Filename of the generated certificate.
42+
43+ - ** Type:** ` string `
44+ - ** Default:** ` 'fake-cert.pem' `
45+ - ** Example:**
46+
47+ ``` ts
48+ pluginBasicSsl ({
49+ filename: ' foo.pem' ,
50+ });
51+ ```
52+
3553## License
3654
3755[ MIT] ( ./LICENSE ) .
Original file line number Diff line number Diff line change @@ -3,16 +3,24 @@ import { resolveHttpsConfig } from './util.js';
33
44export const PLUGIN_BASIC_SSL_NAME = 'rsbuild:basic-ssl' ;
55
6- export function pluginBasicSsl ( ) : RsbuildPlugin {
7- return {
8- name : PLUGIN_BASIC_SSL_NAME ,
9- setup ( api ) {
10- api . modifyRsbuildConfig ( ( config ) => {
11- config . server = {
12- ...config . server ,
13- https : resolveHttpsConfig ( config . server ?. https ) ,
14- } ;
15- } ) ;
16- } ,
17- } ;
18- }
6+ export type PluginBasicSslOptions = {
7+ /**
8+ * Filename of the generated certificate
9+ * @default 'fake-cert.pem'
10+ */
11+ filename ?: string ;
12+ } ;
13+
14+ export const pluginBasicSsl = (
15+ options : PluginBasicSslOptions = { } ,
16+ ) : RsbuildPlugin => ( {
17+ name : PLUGIN_BASIC_SSL_NAME ,
18+ setup ( api ) {
19+ api . modifyRsbuildConfig ( ( config ) => {
20+ config . server = {
21+ ...config . server ,
22+ https : resolveHttpsConfig ( config . server ?. https , options ) ,
23+ } ;
24+ } ) ;
25+ } ,
26+ } ) ;
Original file line number Diff line number Diff line change @@ -2,11 +2,13 @@ import fs from 'node:fs';
22import path from 'node:path' ;
33import type { ServerConfig } from '@rsbuild/core' ;
44import selfsigned from 'selfsigned' ;
5+ import type { PluginBasicSslOptions } from './index.js' ;
56
67type HttpsConfig = ServerConfig [ 'https' ] ;
78
89export const resolveHttpsConfig = (
910 config : HttpsConfig ,
11+ options : PluginBasicSslOptions ,
1012) : {
1113 key : NonNullable < HttpsConfig > [ 'key' ] ;
1214 cert : NonNullable < HttpsConfig > [ 'cert' ] ;
@@ -17,7 +19,7 @@ export const resolveHttpsConfig = (
1719 return { key, cert } ;
1820 }
1921
20- const certPath = path . join ( __dirname , 'fake-cert.pem' ) ;
22+ const certPath = path . join ( __dirname , options . filename ?? 'fake-cert.pem' ) ;
2123
2224 if ( fs . existsSync ( certPath ) ) {
2325 const stats = fs . statSync ( certPath ) ;
Original file line number Diff line number Diff line change 1+ import { dirname } from 'node:path' ;
2+ import { fileURLToPath } from 'node:url' ;
3+ import { expect , test } from '@playwright/test' ;
4+ import { createRsbuild } from '@rsbuild/core' ;
5+ import { pluginBasicSsl } from '../../dist' ;
6+
7+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
8+
9+ test ( 'should print HTTPS server URLs when custom filename' , async ( ) => {
10+ const rsbuild = await createRsbuild ( {
11+ cwd : __dirname ,
12+ rsbuildConfig : {
13+ plugins : [
14+ pluginBasicSsl ( {
15+ filename : 'foo.pem' ,
16+ } ) ,
17+ ] ,
18+ server : {
19+ port : 3100 ,
20+ } ,
21+ } ,
22+ } ) ;
23+
24+ const { server, urls } = await rsbuild . startDevServer ( ) ;
25+
26+ await new Promise ( ( resolve ) => {
27+ rsbuild . onDevCompileDone ( resolve ) ;
28+ } ) ;
29+
30+ expect ( urls . every ( ( url ) => url . startsWith ( 'https' ) ) ) . toBeTruthy ( ) ;
31+
32+ await server . close ( ) ;
33+ } ) ;
Original file line number Diff line number Diff line change 1+ import { pluginBasicSsl } from '@rsbuild/plugin-basic-ssl' ;
2+
3+ export default {
4+ plugins : [ pluginBasicSsl ( ) ] ,
5+ } ;
Original file line number Diff line number Diff line change 1+ console . log ( '1' ) ;
You can’t perform that action at this time.
0 commit comments