forked from jaredpalmer/razzle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request jaredpalmer#1799 from mzvast/plugin-devcert
feat(plugin): add razzle-plugin-devcert
- Loading branch information
Showing
4 changed files
with
214 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# razzle-plugin-devcert | ||
|
||
## Installation | ||
|
||
```bash | ||
yarn add razzle-plugin-devcert | ||
``` | ||
|
||
Add it to your `razzle.config.js`: | ||
|
||
```js | ||
// razzle.config.js | ||
|
||
module.exports = { | ||
plugins: ['devcert'], | ||
}; | ||
``` |
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,55 @@ | ||
'use strict'; | ||
const devcert = require('devcert'); | ||
|
||
module.exports = { | ||
modifyOptions(opts) { | ||
// use modifyOptions so certificateFor is called once | ||
const options = opts.options.razzleOptions; | ||
return new Promise(async resolve => { | ||
const httpsCredentials = await devcert.certificateFor('localhost'); | ||
const stringHttpsCredentials = { | ||
key: httpsCredentials.key.toString(), | ||
cert: httpsCredentials.cert.toString(), | ||
}; | ||
options.HTTPS_CREDENTIALS = stringHttpsCredentials; | ||
resolve(options); | ||
}); | ||
}, | ||
modifyWebpackOptions(opts) { | ||
const razzleOptions = opts.options.razzleOptions; | ||
const webpackOptions = opts.options.webpackOptions; | ||
if (opts.env.target === 'node' && opts.env.dev) { | ||
webpackOptions.definePluginOptions.HTTPS_CREDENTIALS = JSON.stringify( | ||
razzleOptions.HTTPS_CREDENTIALS | ||
); | ||
} | ||
return webpackOptions; | ||
}, | ||
modifyWebpackConfig({ | ||
env: { | ||
target, // the target 'node' or 'web' | ||
dev, // is this a development build? true or false | ||
}, | ||
webpackConfig, // the created webpack config | ||
webpackObject, // the imported webpack node module | ||
options: { | ||
pluginOptions, // the options passed to the plugin ({ name:'pluginname', options: { key: 'value'}}) | ||
razzleOptions, // the modified options passed to Razzle in the `options` key in `razzle.config.js` (options: { key: 'value'}) | ||
webpackOptions, // the modified options that was used to configure webpack/ webpack loaders and plugins | ||
}, | ||
paths, // the modified paths that will be used by Razzle. | ||
}) { | ||
// Do some stuff to webpackConfig | ||
// DevCert配置 | ||
{ | ||
if (target === 'web' && dev) { | ||
webpackConfig.devServer.https = razzleOptions.HTTPS_CREDENTIALS; | ||
webpackConfig.devServer.headers = { | ||
'Access-Control-Allow-Origin': '*', | ||
https: true, | ||
}; | ||
} | ||
} | ||
return webpackConfig; | ||
}, | ||
}; |
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,19 @@ | ||
{ | ||
"name": "razzle-plugin-devcert", | ||
"license": "MIT", | ||
"version": "4.2.13", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com:jaredpalmer/razzle.git", | ||
"directory": "packages/razzle-plugin-devcert" | ||
}, | ||
"main": "index.js", | ||
"dependencies": { | ||
"devcert": "^1.2.0" | ||
}, | ||
"peerDependencies": { | ||
"razzle": "4.2.13", | ||
"razzle-dev-utils": "4.2.13", | ||
"webpack": "~4||~5" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2529,6 +2529,16 @@ | |
"@types/node" "*" | ||
"@types/responselike" "*" | ||
|
||
"@types/configstore@^2.1.1": | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/@types/configstore/-/configstore-2.1.1.tgz#cd1e8553633ad3185c3f2f239ecff5d2643e92b6" | ||
integrity sha1-zR6FU2M60xhcPy8jns/10mQ+krY= | ||
|
||
"@types/debug@^0.0.30": | ||
version "0.0.30" | ||
resolved "https://registry.yarnpkg.com/@types/debug/-/debug-0.0.30.tgz#dc1e40f7af3b9c815013a7860e6252f6352a84df" | ||
integrity sha512-orGL5LXERPYsLov6CWs3Fh6203+dXzJkR7OnddIr2514Hsecwc8xRpzCapshBbKFImCsvS/mk6+FWiN5LyZJAQ== | ||
|
||
"@types/eslint@^7.2.6": | ||
version "7.2.7" | ||
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.2.7.tgz#f7ef1cf0dceab0ae6f9a976a0a9af14ab1baca26" | ||
|
@@ -2542,6 +2552,27 @@ | |
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.46.tgz#0fb6bfbbeabd7a30880504993369c4bf1deab1fe" | ||
integrity sha512-laIjwTQaD+5DukBZaygQ79K1Z0jb1bPEMRrkXSLjtCcZm+abyp5YbrqpSLzD42FwWW6gK/aS4NYpJ804nG2brg== | ||
|
||
"@types/get-port@^3.2.0": | ||
version "3.2.0" | ||
resolved "https://registry.yarnpkg.com/@types/get-port/-/get-port-3.2.0.tgz#f9e0a11443cc21336470185eae3dfba4495d29bc" | ||
integrity sha512-TiNg8R1kjDde5Pub9F9vCwZA/BNW9HeXP5b9j7Qucqncy/McfPZ6xze/EyBdXS5FhMIGN6Fx3vg75l5KHy3V1Q== | ||
|
||
"@types/glob@*": | ||
version "7.2.0" | ||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" | ||
integrity sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA== | ||
dependencies: | ||
"@types/minimatch" "*" | ||
"@types/node" "*" | ||
|
||
"@types/glob@^5.0.34": | ||
version "5.0.37" | ||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-5.0.37.tgz#d0982abc88f9aebbd62099d3d70440cbcea692de" | ||
integrity sha512-ATA/xrS7CZ3A2WCPVY4eKdNpybq56zqlTirnHhhyOztZM/lPxJzusOBI3BsaXbu6FrUluqzvMlI4sZ6BDYMlMg== | ||
dependencies: | ||
"@types/minimatch" "*" | ||
"@types/node" "*" | ||
|
||
"@types/glob@^7.1.1": | ||
version "7.1.3" | ||
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.3.tgz#e6ba80f36b7daad2c685acd9266382e68985c183" | ||
|
@@ -2610,6 +2641,11 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/lodash@^4.14.92": | ||
version "4.14.178" | ||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8" | ||
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw== | ||
|
||
"@types/mdast@^3.0.0": | ||
version "3.0.3" | ||
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.3.tgz#2d7d671b1cd1ea3deb306ea75036c2a0407d2deb" | ||
|
@@ -2627,11 +2663,23 @@ | |
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256" | ||
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg== | ||
|
||
"@types/mkdirp@^0.5.2": | ||
version "0.5.2" | ||
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f" | ||
integrity sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg== | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/node@*", "@types/node@>= 8": | ||
version "14.14.33" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.33.tgz#9e4f8c64345522e4e8ce77b334a8aaa64e2b6c78" | ||
integrity sha512-oJqcTrgPUF29oUP8AsUqbXGJNuPutsetaa9kTQAQce5Lx5dTYWV02ScBiT/k1BX/Z7pKeqedmvp39Wu4zR7N7g== | ||
|
||
"@types/node@^8.5.7": | ||
version "8.10.66" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.66.tgz#dd035d409df322acc83dff62a602f12a5783bbb3" | ||
integrity sha512-tktOkFUA4kXx2hhhrB8bIFb5TbwzS4uOhKEmwiD+NoiL0qtP2OQ9mFldbgD4dV1djrlBYP6eBuQZiWjuHUpqFw== | ||
|
||
"@types/normalize-package-data@^2.4.0": | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e" | ||
|
@@ -2669,6 +2717,14 @@ | |
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/rimraf@^2.0.2": | ||
version "2.0.5" | ||
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.5.tgz#368fb04d59630b727fc05a74d2ca557f64a8ef98" | ||
integrity sha512-YyP+VfeaqAyFmXoTh3HChxOQMyjByRMsHU7kc5KOJkSlXudhMhQIALbYV7rHh/l8d2lX3VUQzprrcAgWdRuU8g== | ||
dependencies: | ||
"@types/glob" "*" | ||
"@types/node" "*" | ||
|
||
"@types/sass@^1.16.0": | ||
version "1.16.0" | ||
resolved "https://registry.yarnpkg.com/@types/sass/-/sass-1.16.0.tgz#b41ac1c17fa68ffb57d43e2360486ef526b3d57d" | ||
|
@@ -2691,6 +2747,11 @@ | |
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.8.tgz#b94a4391c85666c7b73299fd3ad79d4faa435310" | ||
integrity sha512-ipixuVrh2OdNmauvtT51o3d8z12p6LtFW9in7U79der/kwejjdNchQC5UMn5u/KxNoM7VHHOs/l8KS8uHxhODQ== | ||
|
||
"@types/tmp@^0.0.33": | ||
version "0.0.33" | ||
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.0.33.tgz#1073c4bc824754ae3d10cfab88ab0237ba964e4d" | ||
integrity sha1-EHPEvIJHVK49EM+riKsCN7qWTk0= | ||
|
||
"@types/uglify-js@*": | ||
version "3.13.1" | ||
resolved "https://registry.yarnpkg.com/@types/uglify-js/-/uglify-js-3.13.1.tgz#5e889e9e81e94245c75b6450600e1c5ea2878aea" | ||
|
@@ -3210,7 +3271,7 @@ ansi-colors@^4.1.1: | |
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" | ||
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== | ||
|
||
ansi-escapes@^3.0.0, ansi-escapes@^3.2.0: | ||
ansi-escapes@^3.0.0, ansi-escapes@^3.1.0, ansi-escapes@^3.2.0: | ||
version "3.2.0" | ||
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" | ||
integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ== | ||
|
@@ -3290,6 +3351,11 @@ anymatch@^3.0.3, anymatch@~3.1.1: | |
normalize-path "^3.0.0" | ||
picomatch "^2.0.4" | ||
|
||
application-config-path@^0.1.0: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/application-config-path/-/application-config-path-0.1.0.tgz#193c5f0a86541a4c66fba1e2dc38583362ea5e8f" | ||
integrity sha1-GTxfCoZUGkxm+6Hi3DhYM2LqXo8= | ||
|
||
aproba@^1.0.3, aproba@^1.1.1: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" | ||
|
@@ -4874,6 +4940,11 @@ comma-separated-tokens@^1.0.0: | |
resolved "https://registry.yarnpkg.com/comma-separated-tokens/-/comma-separated-tokens-1.0.8.tgz#632b80b6117867a158f1080ad498b2fbe7e3f5ea" | ||
integrity sha512-GHuDRO12Sypu2cV70d1dkA2EUmXHgntrzbpvOB+Qy+49ypNfGgFQIC2fhhXbnyrJRynDCAARsT7Ou0M6hirpfw== | ||
|
||
command-exists@^1.2.4: | ||
version "1.2.9" | ||
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69" | ||
integrity sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w== | ||
|
||
[email protected]: | ||
version "2.15.1" | ||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f" | ||
|
@@ -5860,6 +5931,34 @@ [email protected]: | |
address "^1.0.1" | ||
debug "^2.6.0" | ||
|
||
devcert@^1.2.0: | ||
version "1.2.0" | ||
resolved "https://registry.yarnpkg.com/devcert/-/devcert-1.2.0.tgz#7fb0fa2ca4c73baf3a3053973e80ebc5899fb20d" | ||
integrity sha512-Tca9LUcmDegqTxlnQLTxVARS3MqYT+eWJfskXykefknT9jPoSJEA+t5BkDq5C5Tz+gVmAWmOH5vvKMfLJO/UhQ== | ||
dependencies: | ||
"@types/configstore" "^2.1.1" | ||
"@types/debug" "^0.0.30" | ||
"@types/get-port" "^3.2.0" | ||
"@types/glob" "^5.0.34" | ||
"@types/lodash" "^4.14.92" | ||
"@types/mkdirp" "^0.5.2" | ||
"@types/node" "^8.5.7" | ||
"@types/rimraf" "^2.0.2" | ||
"@types/tmp" "^0.0.33" | ||
application-config-path "^0.1.0" | ||
command-exists "^1.2.4" | ||
debug "^3.1.0" | ||
eol "^0.9.1" | ||
get-port "^3.2.0" | ||
glob "^7.1.2" | ||
lodash "^4.17.4" | ||
mkdirp "^0.5.1" | ||
password-prompt "^1.0.4" | ||
rimraf "^2.6.2" | ||
sudo-prompt "^8.2.0" | ||
tmp "^0.0.33" | ||
tslib "^1.10.0" | ||
|
||
[email protected]: | ||
version "0.0.847576" | ||
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.847576.tgz#2f201bfb68aa9ef4497199fbd7f5d5dfde3b200b" | ||
|
@@ -6230,6 +6329,11 @@ envinfo@^7.3.1: | |
resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.7.4.tgz#c6311cdd38a0e86808c1c9343f667e4267c4a320" | ||
integrity sha512-TQXTYFVVwwluWSFis6K2XKxgrD22jEv0FTuLCQI+OjH7rn93+iY0fSSFM5lrSxFY+H1+B0/cvvlamr3UsBivdQ== | ||
|
||
eol@^0.9.1: | ||
version "0.9.1" | ||
resolved "https://registry.yarnpkg.com/eol/-/eol-0.9.1.tgz#f701912f504074be35c6117a5c4ade49cd547acd" | ||
integrity sha512-Ds/TEoZjwggRoz/Q2O7SE3i4Jm66mqTDfmdHdq/7DKVk3bro9Q8h6WdXKdPqFLMoqxrDK5SVRzHVPOS6uuGtrg== | ||
|
||
err-code@^1.0.0: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/err-code/-/err-code-1.1.2.tgz#06e0116d3028f6aef4806849eb0ea6a748ae6960" | ||
|
@@ -7542,6 +7646,11 @@ get-pkg-repo@^1.0.0: | |
parse-github-repo-url "^1.3.0" | ||
through2 "^2.0.0" | ||
|
||
get-port@^3.2.0: | ||
version "3.2.0" | ||
resolved "https://registry.yarnpkg.com/get-port/-/get-port-3.2.0.tgz#dd7ce7de187c06c8bf353796ac71e099f0980ebc" | ||
integrity sha1-3Xzn3hh8Bsi/NTeWrHHgmfCYDrw= | ||
|
||
get-port@^4.2.0: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119" | ||
|
@@ -12209,6 +12318,14 @@ pascalcase@^0.1.1: | |
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14" | ||
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ= | ||
|
||
password-prompt@^1.0.4: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/password-prompt/-/password-prompt-1.1.2.tgz#85b2f93896c5bd9e9f2d6ff0627fa5af3dc00923" | ||
integrity sha512-bpuBhROdrhuN3E7G/koAju0WjVw9/uQOG5Co5mokNj0MiOSBVZS1JTwM4zl55hu0WFmIEFvO9cU9sJQiBIYeIA== | ||
dependencies: | ||
ansi-escapes "^3.1.0" | ||
cross-spawn "^6.0.5" | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a" | ||
|
@@ -15137,6 +15254,11 @@ stylehacks@^4.0.0: | |
postcss "^7.0.0" | ||
postcss-selector-parser "^3.0.0" | ||
|
||
sudo-prompt@^8.2.0: | ||
version "8.2.5" | ||
resolved "https://registry.yarnpkg.com/sudo-prompt/-/sudo-prompt-8.2.5.tgz#cc5ef3769a134bb94b24a631cc09628d4d53603e" | ||
integrity sha512-rlBo3HU/1zAJUrkY6jNxDOC9eVYliG6nS4JA8u8KAshITd07tafMc/Br7xQwCSseXwJ2iCcHCE8SNWX3q8Z+kw== | ||
|
||
[email protected]: | ||
version "5.4.0" | ||
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54" | ||
|