rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[localization-plugin][set-public-path-plugin] Support emitting locales to separate folders

Open dmichon-msft opened this issue 4 years ago • 1 comments

Summary

set-webpack-public-path-plugin

  • Enables use of the / character in chunk filenames, so that they can live in a subfolder of the public path.

localization-plugin

  • Reworks how assets are generated to avoid deleting assets during the compilation process.
  • Passes the current webpack.compilation.Module object to the resolveMissingTranslatedStrings() so that implementers have access to more information with which to find the translations.
  • Allows the current locale in the runtime chunk to be determined by a runtime ECMAScript expression instead of requiring the runtime to itself have localized variants.

Details

set-webpack-public-path-plugin

  • Ensures that the / character is properly escaped when escaping the filename as a regular expression literal.
  • Uses the index of the regular expression match to compute the public path instead of separately locating the final /.

localization-plugin

  • Moves all filename generation logic to the tap into mainTemplate.hooks.getAssetPath, including for the async chunk path generator
  • Uses ReplaceSource to perform localization changes to assets so that source maps can be properly generated.
  • When generating the filename for a chunk assets, sets [locale] from the options object if a value is provided, otherwise falls back to the default locale if the chunk contains strings, or else the "no strings" locale if it does not. This removes the need for deleting the initial reference asset at emit time, since the reference asset is not created using the path for the default (or unlocalized) locale.
  • Updates the loader to provide the current webpack.compilation.Module object into the plugin and from there to the resolveMissingTranslatedStrings() callback, so that the implementer can use information other than just the resolved asset path to locate the relevant translated strings, for example information that other plugins stash on the factoryMeta property.
  • Favors Map over Record for internal data structures for performance
  • Modifies the JSONP script generation to only require token replacement for the value of the current locale, not the determination of whether or not the target chunk is localized.
  • Compresses the logic to determine whether or not the target chunk is localized at runtime by emitting only the smaller set of localized vs. non-localized chunks and performing a containment check, defaulting to membership in the opposite set.

How it was tested

Using the build test projects:

  • localization-plugin-test-01
  • localization-plugin-test-02
  • localization-plugin-test-03

dmichon-msft avatar Dec 09 '21 22:12 dmichon-msft

Note: PR #3337 has renamed our GitHub master branch to main. This should not affect your pull request, but we recommend to redo your git clone to avoid confusion with the old branch name.

iclanton avatar Apr 09 '22 02:04 iclanton