spfx-fast-serve
Advanced tools
Comparing version 2.0.0-beta.0 to 2.0.0
# Change Log | ||
## [2.0.0] - 23 Apr 2021 | ||
## [2.0.0] - 30 Apr 2021 | ||
@@ -5,0 +5,0 @@ Full codebase re-write with TypeScript, better extensibility and SPFx 1.12 support. |
# SPFx 1.12 notes | ||
SPFx 1.12 changed file name handling for webpack entry points and for resource files. It uses format `[name]_[hash].js`. | ||
In order to make it work with `spfx-fast-serve` correctly, you have to proxy requests from `[resource package name]_[guid].js` for resources to the corresponding files from webpack output inside `spfx-fast-serve`. | ||
SPFx 1.12 changed file name handling for webpack entry points and for resource files. It uses format `[name]_[locale].js`. | ||
In order to make it work with `spfx-fast-serve` correctly, you have to proxy requests from `[resource package name]_[locale].js` for resources to the corresponding files from webpack output inside `spfx-fast-serve`. | ||
@@ -14,3 +14,3 @@ `spfx-fast-serve` uses `[name]` format for filename. So the idea is to extract all `localizedResources` keys from `./config/config.json`, then match them to the entry in `./temp/manifest.json` to handle resources. To handle entry points mapping we can just use a function for webpack's `filename` property. In that function return the same file name, as SPFx returns back, based on `manifests.json`. | ||
2. Open `./temp/manifests.json` and find `loaderConfig.scriptResources` for corresponding entry point. Save path as a key, locale code, map path as values. | ||
3. In `context` function check if saved map contains key which should be equal to a file name, ie. `HelloWorldWebPartStrings_en-us_[guid].js` | ||
3. In `context` function check if saved map contains key which should be equal to a file name, ie. `HelloWorldWebPartStrings_en-us.js` | ||
4. In `pathRewrite` extract map path by key, replace locale code and return a new path. | ||
@@ -39,6 +39,6 @@ | ||
"paths": { | ||
"en-US": "BasicWebpartWebPartStrings_en-us_536e65149b0acf4d52c0043073b9fc59.js", | ||
"nl-NL": "BasicWebpartWebPartStrings_nl-nl_80c584e914de3f2c5ce1b5dda381c304.js" | ||
"en-US": "BasicWebpartWebPartStrings_en-us.js", | ||
"nl-NL": "BasicWebpartWebPartStrings_nl-nl.js" | ||
}, | ||
"defaultPath": "BasicWebpartWebPartStrings_en-us_536e65149b0acf4d52c0043073b9fc59.js" | ||
"defaultPath": "BasicWebpartWebPartStrings_en-us.js" | ||
} | ||
@@ -52,7 +52,7 @@ } | ||
{ | ||
"BasicWebpartWebPartStrings_en-us_536e65149b0acf4d52c0043073b9fc59.js": { | ||
"BasicWebpartWebPartStrings_en-us.js": { | ||
"locale": "en-us", | ||
"mapPath": "src/webparts/helloWorld/loc/en-us.js" | ||
}, | ||
"BasicWebpartWebPartStrings_nl-nl_80c584e914de3f2c5ce1b5dda381c304.js": { | ||
"BasicWebpartWebPartStrings_nl-nl.js": { | ||
"locale": "nl-nl", | ||
@@ -59,0 +59,0 @@ "mapPath": "src/webparts/helloWorld/loc/nl-nl.js" |
@@ -6,3 +6,4 @@ # How to upgrade to 2.x version from 1.x | ||
3. Delete `webpack.js` file. If you have any custom modifications inside `webpack.js`, you should manually move them to a new `fast-serve/webpack.extend.js` file (will be merged with the default `fast-serve/webpack.js`). | ||
4. Run `npm i` | ||
5. Run `npm run serve` | ||
4. Delete `node_modules` and `package.lock.json` | ||
5. Run `npm i` | ||
6. Run `npm run serve` |
@@ -36,8 +36,3 @@ "use strict"; | ||
$schema: consts_1.SchemaUrl, | ||
cli: cliArgs, | ||
serve: { | ||
open: !cliArgs.isLibraryComponent, | ||
fullScreenErrors: true, | ||
loggingLevel: 'normal' | ||
} | ||
cli: cliArgs | ||
}; | ||
@@ -44,0 +39,0 @@ const settings = this.ensureSettings(defaultSettings); |
@@ -17,2 +17,4 @@ const path = require("path"); | ||
setDefaultServeSettings(settings); | ||
const port = settings.cli.isLibraryComponent ? 4320 : 4321; | ||
@@ -184,9 +186,2 @@ const host = "https://localhost:" + port; | ||
stats: getLoggingLevel(settings.serve.loggingLevel), | ||
stats: { | ||
preset: "errors-only", | ||
colors: true, | ||
chunks: false, | ||
modules: false, | ||
assets: false | ||
}, | ||
proxy: { // url re-write for resources to be served directly from src folder | ||
@@ -316,2 +311,17 @@ "/lib/**/loc/*.js": { | ||
function setDefaultServeSettings(settings) { | ||
const defaultServeSettings = { | ||
open: true, | ||
fullScreenErrors: true, | ||
loggingLevel: 'normal' | ||
} | ||
settings.serve = settings.serve || {}; | ||
settings.serve = Object.assign(defaultServeSettings, settings.serve); | ||
if (settings.cli.isLibraryComponent) { | ||
settings.serve.open = false; | ||
} | ||
} | ||
module.exports = webpackMerge(extend.transformConfig(createConfig()), extend.webpackConfig); |
@@ -15,2 +15,4 @@ const path = require("path"); | ||
setDefaultServeSettings(settings); | ||
const port = settings.cli.isLibraryComponent ? 4320 : 4321; | ||
@@ -182,9 +184,2 @@ const host = "https://localhost:" + port; | ||
stats: getLoggingLevel(settings.serve.loggingLevel), | ||
stats: { | ||
preset: "errors-only", | ||
colors: true, | ||
chunks: false, | ||
modules: false, | ||
assets: false | ||
}, | ||
proxy: { // url re-write for resources to be served directly from src folder | ||
@@ -314,2 +309,17 @@ "/lib/**/loc/*.js": { | ||
function setDefaultServeSettings(settings) { | ||
const defaultServeSettings = { | ||
open: true, | ||
fullScreenErrors: true, | ||
loggingLevel: 'normal' | ||
} | ||
settings.serve = settings.serve || {}; | ||
settings.serve = Object.assign(defaultServeSettings, settings.serve); | ||
if (settings.cli.isLibraryComponent) { | ||
settings.serve.open = false; | ||
} | ||
} | ||
module.exports = webpackMerge(extend.transformConfig(createConfig()), extend.webpackConfig); |
@@ -15,2 +15,4 @@ const path = require("path"); | ||
setDefaultServeSettings(settings); | ||
const port = settings.cli.isLibraryComponent ? 4320 : 4321; | ||
@@ -177,9 +179,4 @@ const host = "https://localhost:" + port; | ||
openPage: settings.serve.openUrl ? settings.serve.openUrl : host + "/temp/workbench.html", | ||
stats: { | ||
preset: "errors-only", | ||
colors: true, | ||
chunks: false, | ||
modules: false, | ||
assets: false | ||
}, | ||
overlay: settings.serve.fullScreenErrors, | ||
stats: getLoggingLevel(settings.serve.loggingLevel), | ||
proxy: { // url re-write for resources to be served directly from src folder | ||
@@ -276,2 +273,50 @@ "/lib/**/loc/*.js": { | ||
function getLoggingLevel(level) { | ||
if (level === "minimal") { | ||
return { | ||
all: false, | ||
colors: true, | ||
errors: true | ||
} | ||
} | ||
if (level === "normal") { | ||
return { | ||
all: false, | ||
colors: true, | ||
errors: true, | ||
timings: true, | ||
entrypoints: true | ||
} | ||
} | ||
if (level === "detailed") { | ||
return { | ||
all: false, | ||
colors: true, | ||
errors: true, | ||
timings: true, | ||
assets: true, | ||
warnings: true | ||
} | ||
} | ||
throw new Error("Unsupported log level: " + level); | ||
} | ||
function setDefaultServeSettings(settings) { | ||
const defaultServeSettings = { | ||
open: true, | ||
fullScreenErrors: true, | ||
loggingLevel: 'normal' | ||
} | ||
settings.serve = settings.serve || {}; | ||
settings.serve = Object.assign(defaultServeSettings, settings.serve); | ||
if (settings.cli.isLibraryComponent) { | ||
settings.serve.open = false; | ||
} | ||
} | ||
module.exports = webpackMerge(extend.transformConfig(createConfig()), extend.webpackConfig); |
@@ -16,2 +16,4 @@ const path = require("path"); | ||
setDefaultServeSettings(settings); | ||
const port = settings.cli.isLibraryComponent ? 4320 : 4321; | ||
@@ -395,3 +397,17 @@ const host = "https://localhost:" + port; | ||
function setDefaultServeSettings(settings) { | ||
const defaultServeSettings = { | ||
open: true, | ||
fullScreenErrors: true, | ||
loggingLevel: 'normal' | ||
} | ||
settings.serve = settings.serve || {}; | ||
settings.serve = Object.assign(defaultServeSettings, settings.serve); | ||
if (settings.cli.isLibraryComponent) { | ||
settings.serve.open = false; | ||
} | ||
} | ||
module.exports = webpackMerge(extend.transformConfig(createConfig()), extend.webpackConfig); |
{ | ||
"name": "spfx-fast-serve", | ||
"version": "2.0.0-beta.0", | ||
"version": "2.0.0", | ||
"author": "Sergei Sergeev (https://github.com/s-KaiNet)", | ||
@@ -5,0 +5,0 @@ "description": "Improve your SharePoint Framework development by speeding up 'serve' command", |
@@ -1,2 +0,2 @@ | ||
# SPFx Fast Serve Tool | ||
# :rocket: SPFx Fast Serve Tool | ||
@@ -28,6 +28,28 @@ A command line utility, which modifies your SharePoint Framework solution, so that it runs continuous `serve` command as fast as possible. | ||
> **IMPORTANT!** SharePoint Framework 1.12 and onwards is supported starting from `2.x` version of `spfx-fast-serve` | ||
> **IMPORTANT!** SharePoint Framework 1.12 and onwards is supported starting from `2.x` version of `spfx-fast-serve`. | ||
> | ||
> Minimal supported NodeJS version is 12. | ||
Please use [this guide](/docs/Upgrade%20to%202x.md) if you're planning to migrate your project to `spfx-fast-serve` 2.x. | ||
## Webpack extensibility | ||
Starting from version `2.x`, the library supports webpack extensibility. | ||
In a `./fast-serve` folder you have a file called `webpack.extend.js`. In this file you can put your own logic for webpack, it will not be overwritten by subsequent `spfx-fast-serve` calls. | ||
You can either provide custom `webpackConfig` object, which will be merged using [webpack-merge](https://github.com/survivejs/webpack-merge) module, or use `transformConfig` to even better control over configuration. | ||
Check out [this sample](https://github.com/s-KaiNet/spfx-fast-serve/blob/master/samples/advanced/fast-serve/webpack.extend.js) to see how it works. The sample configures custom path aliases for SPFx. | ||
## Configuration options | ||
Starting from version `2.x`, the library saves your CLI arguments and serve options into the configuration file. The file is located under `./fast-serve/config.json`. | ||
Currently below configuration values are available for `serve`: | ||
- `open` - boolean, default `true`, whether to open a workbench url on startup | ||
- `openUrl` - string, default `undefined`, which url to open. If empty, local workbench will be opened | ||
- `loggingLevel` - string, default `normal`, valid values are `"minimal", "normal", "detailed"`. `minimal` notifies about errors and new builds only, `normal` adds bundle information, `detailed` adds details about each bundle. | ||
- `fullScreenErrors` - boolean, default `true`, whether to show full-screen (overlay) errors. Corresponds to [webpack's dev server overlay](https://webpack.js.org/configuration/dev-server/#devserveroverlay) | ||
## Which SharePoint Framework versions are supported | ||
@@ -34,0 +56,0 @@ |
@@ -45,8 +45,9 @@ { | ||
"type": "string", | ||
"enum": ["minimal", "normal", "detailed"] | ||
"enum": [ | ||
"minimal", | ||
"normal", | ||
"detailed" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"open", "fullScreenErrors", "loggingLevel" | ||
] | ||
} | ||
} | ||
@@ -59,2 +60,1 @@ }, | ||
} | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
565945
13821
0
132
0