spfx-fast-serve
Advanced tools
Comparing version 2.0.1 to 2.0.2
# Change Log | ||
## [2.0.2] - 06 May 2021 | ||
### Features | ||
- simplified localized resource resolution process | ||
## [2.0.1] - 05 May 2021 | ||
@@ -4,0 +10,0 @@ |
@@ -233,3 +233,2 @@ const path = require("path"); | ||
const modulesMap = {}; | ||
const localizedPathMap = {}; | ||
const originalEntries = Object.keys(originalWebpackConfig.entry); | ||
@@ -247,4 +246,2 @@ | ||
} | ||
extractLocalizedPaths(jsModule.loaderConfig.scriptResources, localizedPathMap, localizedResources); | ||
} | ||
@@ -263,17 +260,8 @@ } | ||
baseConfig.devServer.proxy = [{ | ||
target: host, | ||
secure: false, | ||
context: createProxyContext(localizedPathMap), | ||
pathRewrite: pathRewrite(localizedPathMap) | ||
}]; | ||
addCopyLocalizedResources(localizedResources); | ||
if (settings.cli.isLibraryComponent) { | ||
addCopyPlugin(localizedResources); | ||
} | ||
return baseConfig; | ||
} | ||
function addCopyPlugin(localizedResources) { | ||
function addCopyLocalizedResources(localizedResources) { | ||
const patterns = []; | ||
@@ -298,62 +286,2 @@ for (const resourceKey in localizedResources) { | ||
function extractLocalizedPaths(scriptResources, localizedPathMap, localizedResources) { | ||
const resourceKeys = Object.keys(localizedResources); | ||
for (const resourceKey of resourceKeys) { | ||
if (!scriptResources[resourceKey]) { | ||
continue; | ||
} | ||
const resource = scriptResources[resourceKey]; | ||
if (resource.path) { | ||
const jsPath = resource.path; | ||
const fileNameWithoutExt = path.basename(jsPath, ".js"); | ||
const underscoreIndex = fileNameWithoutExt.lastIndexOf("_"); | ||
const localeCode = fileNameWithoutExt.substr(underscoreIndex + 1); | ||
localizedPathMap[jsPath] = { | ||
locale: localeCode.toLowerCase(), | ||
mapPath: localizedResources[resourceKey].replace(/^lib/gi, "src").replace("{locale}", localeCode.toLowerCase()) // src/webparts/helloWorld/loc/{locale}.js | ||
}; | ||
} | ||
if (resource.paths) { | ||
for (const localeCode in resource.paths) { | ||
const jsPath = resource.paths[localeCode]; | ||
localizedPathMap[jsPath] = { | ||
locale: localeCode.toLowerCase(), | ||
mapPath: localizedResources[resourceKey].replace(/^lib/gi, "src").replace("{locale}", localeCode.toLowerCase()) // src/webparts/helloWorld/loc/{locale}.js | ||
}; | ||
} | ||
} | ||
} | ||
} | ||
function pathRewrite(localizedPathMap) { | ||
return function (requestPath) { | ||
const fileName = path.basename(requestPath); | ||
// we should rewrite localized resource path | ||
if (localizedPathMap[fileName]) { | ||
const resource = localizedPathMap[fileName]; | ||
return "/" + resource.mapPath; | ||
} | ||
return requestPath; | ||
} | ||
} | ||
// rewrite only .js files - all localization files | ||
function createProxyContext(localizedPathMap) { | ||
return function (requestPath) { | ||
const fileName = path.basename(requestPath); | ||
// if localized resource - HelloWorldWebPartStrings_en-us_<guid>.js - rewrite | ||
if (localizedPathMap[fileName]) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
function getEntryPoints(entry) { | ||
@@ -360,0 +288,0 @@ // fix: ".js" entry needs to be ".ts" |
{ | ||
"name": "spfx-fast-serve", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "Sergei Sergeev (https://github.com/s-KaiNet)", | ||
@@ -5,0 +5,0 @@ "description": "Improve your SharePoint Framework development by speeding up 'serve' command", |
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
567207
13783