@atlassian/webresource-webpack-plugin 4.10.2-64a2ef2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +20 -0
- package/.eslintrc +72 -0
- package/.nvmrc +1 -0
- package/.prettierrc +6 -0
- package/CHANGELOG.md +318 -0
- package/CONTRIBUTING.md +92 -0
- package/LICENSE +13 -0
- package/README.md +709 -0
- package/RELEASE.md +17 -0
- package/package.json +118 -0
- package/src/AppResources.js +198 -0
- package/src/QUnitTestResources.js +88 -0
- package/src/WebpackHelpers.js +176 -0
- package/src/WebpackRuntimeHelpers.js +7 -0
- package/src/WrmPlugin.js +676 -0
- package/src/defaults/builtInProvidedDependencies.js +22 -0
- package/src/flattenReduce.js +1 -0
- package/src/helpers/options-parser.js +32 -0
- package/src/helpers/provided-dependencies.js +21 -0
- package/src/helpers/string.js +12 -0
- package/src/helpers/web-resource-entrypoints.js +66 -0
- package/src/helpers/web-resource-generator.js +138 -0
- package/src/helpers/web-resource-parser.js +44 -0
- package/src/helpers/xml.js +44 -0
- package/src/logger.js +28 -0
- package/src/mergeMaps.js +32 -0
- package/src/renderCondition.js +29 -0
- package/src/renderTransformation.js +44 -0
- package/src/settings/base-dependencies.js +42 -0
- package/src/shims/qunit-require-shim.js +19 -0
- package/src/types/typedefs.js +50 -0
- package/src/webpack-modules/EmptyExportsModule.js +26 -0
- package/src/webpack-modules/ProvidedExternalDependencyModule.js +30 -0
- package/src/webpack-modules/WrmDependencyModule.js +12 -0
- package/src/webpack-modules/WrmResourceModule.js +33 -0
- package/test/.eslintrc +11 -0
- package/test/unit/ProvidedExternalDependencyModule.test.js +63 -0
- package/test/unit/WebpackHelpers.test.js +37 -0
- package/test/unit/renderCondition.test.js +240 -0
- package/test/unit/renderTransformation.test.js +69 -0
- package/test/unit/webpack-modules/WrmDependencyModule.test.js +24 -0
- package/test/use-cases/.eslintrc +14 -0
- package/test/use-cases/asset-content-type/asset-content-type.test.js +50 -0
- package/test/use-cases/asset-content-type/src/app.js +8 -0
- package/test/use-cases/asset-content-type/src/ice.png +0 -0
- package/test/use-cases/asset-content-type/src/rect.svg +4 -0
- package/test/use-cases/asset-content-type/webpack.config.js +33 -0
- package/test/use-cases/asset-loading-via-js/asset-loading-via-js.test.js +61 -0
- package/test/use-cases/asset-loading-via-js/src/app.js +8 -0
- package/test/use-cases/asset-loading-via-js/src/ice.png +0 -0
- package/test/use-cases/asset-loading-via-js/src/rect.svg +4 -0
- package/test/use-cases/asset-loading-via-js/webpack.config.js +31 -0
- package/test/use-cases/associations-complex/associations-complex.test.js +82 -0
- package/test/use-cases/associations-complex/package-lock.json +73 -0
- package/test/use-cases/associations-complex/package.json +9 -0
- package/test/use-cases/associations-complex/src/copied-file-should-be-ignored.js +0 -0
- package/test/use-cases/associations-complex/src/entry.js +5 -0
- package/test/use-cases/associations-complex/src/entry2.js +5 -0
- package/test/use-cases/associations-complex/src/qunit.tests.js +2 -0
- package/test/use-cases/associations-complex/src/to-be-chunked.js +1 -0
- package/test/use-cases/associations-complex/webpack.config.js +48 -0
- package/test/use-cases/associations-simple/associations-simple.test.js +65 -0
- package/test/use-cases/associations-simple/package-lock.json +69 -0
- package/test/use-cases/associations-simple/package.json +5 -0
- package/test/use-cases/associations-simple/src/simple.js +3 -0
- package/test/use-cases/associations-simple/webpack.config.js +27 -0
- package/test/use-cases/async-chunks/async-chunks.test.js +113 -0
- package/test/use-cases/async-chunks/src/app.js +9 -0
- package/test/use-cases/async-chunks/src/async-bar.js +4 -0
- package/test/use-cases/async-chunks/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks/webpack.config.js +40 -0
- package/test/use-cases/async-chunks-named-context/async-chunks-named-context.test.js +76 -0
- package/test/use-cases/async-chunks-named-context/src/app.js +9 -0
- package/test/use-cases/async-chunks-named-context/src/app2.js +5 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-named-context/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-named-context/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-named-context/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-named-context/webpack.config.js +43 -0
- package/test/use-cases/async-chunks-of-async-chunks/async-chunks-of-async-chunks.test.js +117 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/app.js +9 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-of-async-chunks/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-of-async-chunks/webpack.config.js +43 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/async-chunks-of-async-chunks-with-multiple-entrypoints.test.js +156 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app.js +9 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/app2.js +5 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-async-bar.js +4 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar-two.js +1 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-async-bar.js +6 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-bar.js +7 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/src/async-foo.js +2 -0
- package/test/use-cases/async-chunks-of-async-chunks-with-multiple-entrypoints/webpack.config.js +43 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/css-and-assets-distribution-via-mini-css-extract-plugin.test.js +72 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app.js +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/app2.js +6 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/ice2.jpg +0 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect.svg +4 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/rect2.svg +4 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles.css +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/src/styles2.css +8 -0
- package/test/use-cases/css-and-assets-distribution-via-mini-css-extract-plugin/webpack.config.js +51 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/css-and-assets-via-extract-text-plugin.test.js +87 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.css +7 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-one.js +3 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.css +3 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/feature-two.js +1 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-via-extract-text-plugin/webpack.config.js +46 -0
- package/test/use-cases/css-and-assets-via-style-loader/css-and-assets-via-style-loader.test.js +46 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/app.js +6 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/ice.png +0 -0
- package/test/use-cases/css-and-assets-via-style-loader/src/styles.css +7 -0
- package/test/use-cases/css-and-assets-via-style-loader/webpack.config.js +46 -0
- package/test/use-cases/cyclic-dependencies/cyclic.test.js +24 -0
- package/test/use-cases/cyclic-dependencies/src/a.js +3 -0
- package/test/use-cases/cyclic-dependencies/src/b.js +3 -0
- package/test/use-cases/cyclic-dependencies/src/root.js +3 -0
- package/test/use-cases/cyclic-dependencies/webpack.config.js +24 -0
- package/test/use-cases/data-providers/data-providers.test.js +111 -0
- package/test/use-cases/data-providers/src/first.js +2 -0
- package/test/use-cases/data-providers/src/second.js +2 -0
- package/test/use-cases/data-providers/src/third.js +2 -0
- package/test/use-cases/data-providers/webpack.config.js +73 -0
- package/test/use-cases/data-providers/webpack.config.with-map.js +33 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/ensure-runtime-overwrite-of-mini-css-extract-plugin.test.js +86 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app.js +5 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/app2.js +5 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice.png +0 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/ice2.jpg +0 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect.svg +4 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/rect2.svg +4 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles.css +8 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/src/styles2.css +8 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.after.config.js +51 -0
- package/test/use-cases/ensure-runtime-overwrite-of-mini-css-extract-plugin/webpack.before.config.js +51 -0
- package/test/use-cases/jsonp-function-name/jsonp-function-name.test.js +37 -0
- package/test/use-cases/jsonp-function-name/src/app.js +1 -0
- package/test/use-cases/jsonp-function-name/src/foo.js +2 -0
- package/test/use-cases/jsonp-function-name/webpack.config.js +35 -0
- package/test/use-cases/jsonp-function-name-default/jsonp-function-name-default.test.js +39 -0
- package/test/use-cases/jsonp-function-name-default/src/app.js +1 -0
- package/test/use-cases/jsonp-function-name-default/src/foo.js +2 -0
- package/test/use-cases/jsonp-function-name-default/webpack.config.js +34 -0
- package/test/use-cases/location-prefix/location-prefix.test.js +29 -0
- package/test/use-cases/location-prefix/src/simple.js +6 -0
- package/test/use-cases/location-prefix/webpack.config.js +25 -0
- package/test/use-cases/provided-module-replacement/provided-module-replacement.test.js +63 -0
- package/test/use-cases/provided-module-replacement/src/app.js +3 -0
- package/test/use-cases/provided-module-replacement/webpack.config.with-map.js +33 -0
- package/test/use-cases/provided-module-replacement/webpack.config.with-object.js +34 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/provided-modules-replacement-with-amd-target.test.js +62 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/src/app.js +3 -0
- package/test/use-cases/provided-modules-replacement-with-amd-target/webpack.config.js +41 -0
- package/test/use-cases/qunit-test-wrm-web-resource/qunit-test-wrm-web-resource.test.js +157 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/app.2.js +6 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/app.js +8 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep.js +8 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/bar-dep_test.js +1 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-async.js +3 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep.js +4 -0
- package/test/use-cases/qunit-test-wrm-web-resource/src/foo-dep_test.js +1 -0
- package/test/use-cases/qunit-test-wrm-web-resource/webpack.config.js +24 -0
- package/test/use-cases/resource-parameters/resource-parameters.test.js +77 -0
- package/test/use-cases/resource-parameters/src/app.js +12 -0
- package/test/use-cases/resource-parameters/src/ice.png +0 -0
- package/test/use-cases/resource-parameters/src/ice2.jpg +0 -0
- package/test/use-cases/resource-parameters/src/rect.svg +4 -0
- package/test/use-cases/resource-parameters/webpack.config.js +62 -0
- package/test/use-cases/resource-parameters/webpack.svg.config.js +30 -0
- package/test/use-cases/simple/simple.test.js +83 -0
- package/test/use-cases/simple/src/simple.js +3 -0
- package/test/use-cases/simple/webpack.config.js +24 -0
- package/test/use-cases/single-runtime-chunk/single-runtime-chunk.test.js +132 -0
- package/test/use-cases/single-runtime-chunk/src/first.js +2 -0
- package/test/use-cases/single-runtime-chunk/src/second.js +2 -0
- package/test/use-cases/single-runtime-chunk/src/shared.js +3 -0
- package/test/use-cases/single-runtime-chunk/src/third.js +2 -0
- package/test/use-cases/single-runtime-chunk/webpack.config.js +33 -0
- package/test/use-cases/specify-asset-dev-hash/specify-asset-dev-hash.test.js +33 -0
- package/test/use-cases/specify-asset-dev-hash/src/feature.js +6 -0
- package/test/use-cases/specify-asset-dev-hash/src/library.js +6 -0
- package/test/use-cases/specify-asset-dev-hash/webpack.config.js +71 -0
- package/test/use-cases/specify-conditions/specify-conditions.test.js +106 -0
- package/test/use-cases/specify-conditions/src/app.js +5 -0
- package/test/use-cases/specify-conditions/webpack.config.js +65 -0
- package/test/use-cases/specify-explicit-context/specify-explicit-context.test.js +89 -0
- package/test/use-cases/specify-explicit-context/src/app.js +5 -0
- package/test/use-cases/specify-explicit-context/webpack.config.js +34 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/specify-explicit-context-no-autogenerated.test.js +84 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/src/app.js +5 -0
- package/test/use-cases/specify-explicit-context-no-autogenerated/webpack.config.js +35 -0
- package/test/use-cases/specify-explicit-name/specify-explicit-name.test.js +110 -0
- package/test/use-cases/specify-explicit-name/src/app.js +5 -0
- package/test/use-cases/specify-explicit-name/webpack.config.js +43 -0
- package/test/use-cases/specify-explicit-state/specify-explicit-state.test.js +96 -0
- package/test/use-cases/specify-explicit-state/src/app.js +5 -0
- package/test/use-cases/specify-explicit-state/webpack.config.js +51 -0
- package/test/use-cases/specify-transformation/disable-transformations.test.js +77 -0
- package/test/use-cases/specify-transformation/extend-transformations.test.js +69 -0
- package/test/use-cases/specify-transformation/specify-transformation.test.js +100 -0
- package/test/use-cases/specify-transformation/src/app.js +13 -0
- package/test/use-cases/specify-transformation/src/ice.png +0 -0
- package/test/use-cases/specify-transformation/src/rect.svg +4 -0
- package/test/use-cases/specify-transformation/src/test.html +1 -0
- package/test/use-cases/specify-transformation/src/test.less +1 -0
- package/test/use-cases/specify-transformation/src/test.txt +1 -0
- package/test/use-cases/specify-transformation/webpack.disable-tranformations.config.js +31 -0
- package/test/use-cases/specify-transformation/webpack.extend-tranformations.config.js +34 -0
- package/test/use-cases/specify-transformation/webpack.specify-transformations.config.js +35 -0
- package/test/use-cases/split-chunks/split-chunks.test.js +102 -0
- package/test/use-cases/split-chunks/src/app.js +7 -0
- package/test/use-cases/split-chunks/src/app2.js +7 -0
- package/test/use-cases/split-chunks/src/bar.js +2 -0
- package/test/use-cases/split-chunks/src/foo.js +2 -0
- package/test/use-cases/split-chunks/src/foo2.js +2 -0
- package/test/use-cases/split-chunks/webpack.config.js +42 -0
- package/test/use-cases/split-chunks-with-runtime/split-chunks-with-runtime.test.js +114 -0
- package/test/use-cases/split-chunks-with-runtime/src/app.js +7 -0
- package/test/use-cases/split-chunks-with-runtime/src/app2.js +7 -0
- package/test/use-cases/split-chunks-with-runtime/src/bar.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/src/foo.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/src/foo2.js +2 -0
- package/test/use-cases/split-chunks-with-runtime/webpack.config.js +43 -0
- package/test/use-cases/split-chunks-with-tests/split-chunks-with-tests.test.js +216 -0
- package/test/use-cases/split-chunks-with-tests/src/app.js +7 -0
- package/test/use-cases/split-chunks-with-tests/src/app2.js +7 -0
- package/test/use-cases/split-chunks-with-tests/src/bar.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/bar_test.js +1 -0
- package/test/use-cases/split-chunks-with-tests/src/foo.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/foo2.js +2 -0
- package/test/use-cases/split-chunks-with-tests/src/foo_test.js +1 -0
- package/test/use-cases/split-chunks-with-tests/webpack.config.js +43 -0
- package/test/use-cases/standalone/src/standalone-1.js +1 -0
- package/test/use-cases/standalone/src/standalone-2.js +1 -0
- package/test/use-cases/standalone/standalone.test.js +53 -0
- package/test/use-cases/standalone/webpack.config.js +25 -0
- package/test/use-cases/wrm-dependency-loading/src-amd/app.js +7 -0
- package/test/use-cases/wrm-dependency-loading/src-es6/app.js +7 -0
- package/test/use-cases/wrm-dependency-loading/webpack.config.amd.js +22 -0
- package/test/use-cases/wrm-dependency-loading/webpack.config.es6.js +22 -0
- package/test/use-cases/wrm-dependency-loading/wrm-dependency-loading.test.js +60 -0
- package/test/use-cases/wrm-manifest-path/src/a.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/app.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/app2.js +3 -0
- package/test/use-cases/wrm-manifest-path/src/b.js +3 -0
- package/test/use-cases/wrm-manifest-path/webpack.config.js +27 -0
- package/test/use-cases/wrm-manifest-path/wrm-manifest-path.test.js +57 -0
- package/test/use-cases/wrm-resource-loading/src-amd/app.js +6 -0
- package/test/use-cases/wrm-resource-loading/src-es6/app.js +5 -0
- package/test/use-cases/wrm-resource-loading/src-relative/app.js +5 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.amd.js +23 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.es6.js +23 -0
- package/test/use-cases/wrm-resource-loading/webpack.config.relative.js +23 -0
- package/test/use-cases/wrm-resource-loading/wrm-resource-loading.test.js +89 -0
package/README.md
ADDED
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
# Atlassian Web-Resource Webpack Plugin
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
Auto-generates web-resource definitions from your webpacked code, for usage
|
|
8
|
+
in an Atlassian product or plugin.
|
|
9
|
+
|
|
10
|
+
## Why?
|
|
11
|
+
|
|
12
|
+
[Atlassian's P2 plugin system][atlassian-p2] was shipped in 2008. At the time, the dependency management
|
|
13
|
+
system in P2 -- [the Web Resource Manager, or WRM][atlassian-wrm] -- was a godsend for managing the growing
|
|
14
|
+
complexity of the front-end resources. It offered, amongst other things:
|
|
15
|
+
|
|
16
|
+
* The ability to specify bundles of related resources, called a "web-resource".
|
|
17
|
+
* The ability to specify inter-dependencies of web-resources, so that
|
|
18
|
+
* Batching of necessary code in production could be achieved, and
|
|
19
|
+
* Source order could be maintained.
|
|
20
|
+
|
|
21
|
+
Fast-forward to 2017, and front-end development is drastically different than it was back then.
|
|
22
|
+
JavaScript module systems and webpack have solved many of the problems the WRM initially set
|
|
23
|
+
out to.
|
|
24
|
+
|
|
25
|
+
Unfortunately, Atlassian's plugin system doesn't speak webpack. Happily, though, we can teach
|
|
26
|
+
webpack to speak Atlassian-Plugin. That's what this plugin does.
|
|
27
|
+
|
|
28
|
+
## What does it do?
|
|
29
|
+
|
|
30
|
+
When you add this plugin to your webpack configuration, it will generate an XML file
|
|
31
|
+
with the various WRM configuration necessary to make your code run in an Atlassian product.
|
|
32
|
+
|
|
33
|
+
You will be able to write your plugin's front-end code using any JavaScript module system.
|
|
34
|
+
This plugin will figure out how to turn all of it in to the correct `<web-resource>` declarations,
|
|
35
|
+
along with the appropriate `<dependency>` declarations so that your code ends up loading
|
|
36
|
+
in the right order at a product's runtime.
|
|
37
|
+
|
|
38
|
+
This plugin supports and generates correct WRM output for the following webpack behaviours:
|
|
39
|
+
|
|
40
|
+
* a `<web-resource>` per webpack entry point
|
|
41
|
+
* correct `<web-resource>`s for code-splitting / loading asynchronous chunks
|
|
42
|
+
* loading of non-JavaScript resources (via `ExtractTextPlugin` and friends).
|
|
43
|
+
|
|
44
|
+
## How to use the plugin
|
|
45
|
+
|
|
46
|
+
### Basic setup
|
|
47
|
+
|
|
48
|
+
Add this plugin to your webpack config. For every entry point webpack generates,
|
|
49
|
+
an appropriate `<web-resource>` definition will be generated in an XML file for you,
|
|
50
|
+
which can then be bundled in to your Atlassian product or plugin, ready to be served
|
|
51
|
+
to the browser at product runtime.
|
|
52
|
+
|
|
53
|
+
Given this webpack config:
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
const WrmPlugin = require('atlassian-webresource-webpack-plugin');
|
|
57
|
+
|
|
58
|
+
module.exports = {
|
|
59
|
+
entry: {
|
|
60
|
+
'my-feature': path.join(FRONTEND_SRC_DIR, 'simple.js')
|
|
61
|
+
},
|
|
62
|
+
plugins: [
|
|
63
|
+
new WrmPlugin({
|
|
64
|
+
pluginKey: 'my.full.plugin.artifact-id',
|
|
65
|
+
contextMap: {
|
|
66
|
+
'my-feature': ['atl.general']
|
|
67
|
+
},
|
|
68
|
+
xmlDescriptors: path.resolve(OUTPUT_DIR, 'META-INF', 'plugin-descriptors', 'wr-defs.xml')
|
|
69
|
+
}),
|
|
70
|
+
],
|
|
71
|
+
output: {
|
|
72
|
+
filename: 'bundled.[name].js',
|
|
73
|
+
path: path.resolve(OUTPUT_DIR)
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The output will go to `<OUTPUT_DIR>/META-INF/plugin-descriptors/wr-defs.xml`, and look something like this:
|
|
79
|
+
|
|
80
|
+
```xml
|
|
81
|
+
<bundles>
|
|
82
|
+
|
|
83
|
+
<web-resource key="entrypoint-my-feature">
|
|
84
|
+
<transformation extension="js">
|
|
85
|
+
<transformer key="jsI18n"/>
|
|
86
|
+
</transformation>
|
|
87
|
+
<context>atl.general</context>
|
|
88
|
+
<resource name="bundled.my-feature.js" type="download" location="bundled.my-feature.js" />
|
|
89
|
+
</web-resource>
|
|
90
|
+
|
|
91
|
+
</bundles>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### Consuming the output in your P2 plugin
|
|
95
|
+
|
|
96
|
+
In your P2 plugin project's `pom.xml` file, add the
|
|
97
|
+
`META-INF/plugin-descriptors` directory as a value to an `<Atlassian-Scan-Folders>` tag
|
|
98
|
+
in the `<instruction>` section of the AMPS plugin's build configuration.
|
|
99
|
+
|
|
100
|
+
```xml
|
|
101
|
+
<build>
|
|
102
|
+
<plugins>
|
|
103
|
+
<plugin>
|
|
104
|
+
<!-- START of a bunch of stuff that is probably different for your plugin, but is outside
|
|
105
|
+
the scope of this demonstration -->
|
|
106
|
+
<groupId>com.atlassian.maven.plugins</groupId>
|
|
107
|
+
<artifactId>maven-amps-plugin</artifactId>
|
|
108
|
+
<version>6.2.11</version>
|
|
109
|
+
<!-- END differences with your plugin -->
|
|
110
|
+
<configuration>
|
|
111
|
+
<instructions>
|
|
112
|
+
<Atlassian-Scan-Folders>META-INF/plugin-descriptors</Atlassian-Scan-Folders>
|
|
113
|
+
</instructions>
|
|
114
|
+
</configuration>
|
|
115
|
+
</plugin>
|
|
116
|
+
</plugins>
|
|
117
|
+
</build>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Demonstration P2 plugin usage
|
|
121
|
+
|
|
122
|
+
You can see a demonstration P2 plugin using the webpack plugin here: [sao4fed-bundle-the-ui][101]
|
|
123
|
+
|
|
124
|
+
* Watch this AtlasCamp 2018 talk which uses this plugin amongst others to make your devloop super fast: https://youtu.be/VamdjcJCc0Y
|
|
125
|
+
* Watch this AtlasCamp 2017 talk about how to build and integrate your own front-end devtooling on top of P2, which introduced the alpha version of this plugin: https://youtu.be/2yf-TzKerVQ?t=537
|
|
126
|
+
|
|
127
|
+
## Features
|
|
128
|
+
|
|
129
|
+
### Code splitting
|
|
130
|
+
|
|
131
|
+
If you write your code using any of Webpack's code-splitting techniques, such as calling `require.ensure`,
|
|
132
|
+
this plugin will automatically generate `<web-resource>` definitions for them, and
|
|
133
|
+
automatically translate them in to the appropriate calls to load them asynchronously at an Atlassian
|
|
134
|
+
product's runtime.
|
|
135
|
+
|
|
136
|
+
In other words, there's practically no effort on your part to make your critical path small :)
|
|
137
|
+
|
|
138
|
+
### Flexible generation of `web-resource` definitions
|
|
139
|
+
|
|
140
|
+
By default, a generated web-resource will have:
|
|
141
|
+
|
|
142
|
+
* A key based on the name of your webpack entry-point, and
|
|
143
|
+
* Will be included in a `<context>` named after your entry-point.
|
|
144
|
+
|
|
145
|
+
For example, an entry point named "my-feature" will yield a web-resource like this:
|
|
146
|
+
|
|
147
|
+
```xml
|
|
148
|
+
<web-resource key="entrypoint-my-feature">
|
|
149
|
+
<context>my-feature</context>
|
|
150
|
+
<!-- the resources for your entry-point -->
|
|
151
|
+
</web-resource>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
For new code, this should be enough to get your feature loading in to a place you want it to in your
|
|
155
|
+
plugin or product -- assuming the appropriate call on the server-side is made to include your web-resource.
|
|
156
|
+
|
|
157
|
+
Sometimes, in order to ensure your code loads when it's expected to, you will need to override
|
|
158
|
+
the values generated for you. To do this, when defining the `WrmPlugin`'s config, you can provide either:
|
|
159
|
+
|
|
160
|
+
* A `webresourceKeyMap` to change the web-resource's key or name to whatever you need it to be, or
|
|
161
|
+
* A `contextMap` to include the web-resource in any number of web-resource contexts you expect it to load in to.
|
|
162
|
+
|
|
163
|
+
It's most likely that you'll want to specify additional contexts for a web-resource to load in to. When
|
|
164
|
+
all of your web-resources are automatically generated and loaded via contexts, there is no need to know its key. You
|
|
165
|
+
would typically provide your own web-resource key when refactoring old code to Webpack, in order to keep
|
|
166
|
+
the dependencies working in any pre-existing code.
|
|
167
|
+
|
|
168
|
+
### Module-mapping to `web-resource`s
|
|
169
|
+
|
|
170
|
+
If you use a common library or module -- for example, 'jquery' or 'backbone' -- and you know
|
|
171
|
+
that this module is provided by a P2 plugin in the product's runtime, you can map your usage
|
|
172
|
+
of the module to the `web-resource` that provides it.
|
|
173
|
+
|
|
174
|
+
All you need to do is declare the appropriate webpack `external` for your module, and add an entry
|
|
175
|
+
for the external in the `providedDependencies` configuration of this plugin. When your code is
|
|
176
|
+
compiled, this plugin will automatically add an appropriate `web-resource` dependency that
|
|
177
|
+
will guarantee your code loads after its dependants, and will prevent your bundle from getting too large.
|
|
178
|
+
|
|
179
|
+
For details, check the `providedDependencies` section in the configuration section.
|
|
180
|
+
|
|
181
|
+
### Legacy `web-resource` inclusion
|
|
182
|
+
|
|
183
|
+
90% of the time, your JavaScript code should be declaring explicit dependencies on other modules.
|
|
184
|
+
In the remaining 10% of cases, you may need to lean on the WRM at runtime to ensure your code loads in
|
|
185
|
+
the right order. 9% of the time, the module-mapping feature should be enough for you. In the remaining
|
|
186
|
+
1%, you may just need to add a `web-resource` dependency to force the ordering.
|
|
187
|
+
|
|
188
|
+
You can add import statements to your code that will add a `<dependency>` to your generated web-resource.
|
|
189
|
+
|
|
190
|
+
To include `web-resource`s from exported by _this_ plugin you can use short notation like:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// in AMD syntax
|
|
194
|
+
define(function(require) {
|
|
195
|
+
require('wr-dependency!my-webresource');
|
|
196
|
+
console.log('my-webresource will have been loaded synchronously with the page');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// in ES6
|
|
200
|
+
import 'wr-dependency!my-webresource');
|
|
201
|
+
|
|
202
|
+
console.log('my-webresource will have been loaded synchronously with the page');
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
To include resources exported by _other_ plugins, provide full plugin key:
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
// in AMD syntax
|
|
209
|
+
define(function(require) {
|
|
210
|
+
require('wr-dependency!com.atlassian.auiplugin:dialog2');
|
|
211
|
+
console.log('webresource will have been loaded synchronously with the page');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// in ES6 syntax
|
|
215
|
+
import 'wr-dependency!com.atlassian.auiplugin:dialog2';
|
|
216
|
+
|
|
217
|
+
console.log('webresource will have been loaded synchronously with the page');
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### Legacy runtime `resource` inclusion
|
|
221
|
+
|
|
222
|
+
95% of the time, your application's non-JavaScript resources -- CSS, images, templates, etcetera --
|
|
223
|
+
are possible to bundle and include via Webpack loaders. Sometimes, though, you will have
|
|
224
|
+
resources that only work during an Atlassian product's runtime -- think things like
|
|
225
|
+
Atlassian Soy templates and a product's LESS files for look-and-feel styles -- and
|
|
226
|
+
it isn't possible to make them work during ahead-of-time compilation.
|
|
227
|
+
|
|
228
|
+
In these cases, you can add import statements to your code that will add a `<resource>` to your
|
|
229
|
+
generated web-resource:
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
// in AMD syntax
|
|
233
|
+
define(function(require) {
|
|
234
|
+
require('wr-resource!my-runtime-styles.css!path/to/the/styles.less');
|
|
235
|
+
require('wr-resource!my-compiled-templates.js!path/to/the/templates.soy');
|
|
236
|
+
|
|
237
|
+
console.log('these styles and templates will be transformed to CSS and JS at product runtime.');
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// in ES6 syntax
|
|
241
|
+
import 'wr-resource!my-runtime-styles.css!path/to/the/styles.less';
|
|
242
|
+
import 'wr-resource!my-compiled-templates.js!path/to/the/templates.soy';
|
|
243
|
+
|
|
244
|
+
console.log('these styles and templates will be transformed to CSS and JS at product runtime.');
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Legacy runtime test inclusion
|
|
248
|
+
|
|
249
|
+
If you use the [Atlassian QUnit plugin][104] to write runtime tests, you may be writing tests half-way
|
|
250
|
+
between unit tests and black-box integration tests. If your tests expect that certain modules exist,
|
|
251
|
+
but those modules are compiled and hidden away via Webpack, those tests won't work well with
|
|
252
|
+
your webpacked code.
|
|
253
|
+
|
|
254
|
+
The preferred approach for migrating to webpack is that you refactor your runtime QUnit tests, either
|
|
255
|
+
in to pure unit tests that can run at build-time (e.g., using Jest or Mocha), or
|
|
256
|
+
in to pure black-box integration tests that do not need references to any modules or other
|
|
257
|
+
implementation details (e.g., using Webdriver).
|
|
258
|
+
|
|
259
|
+
If these approaches are not achievable in the short term, you can keep your legacy QUnit tests
|
|
260
|
+
running by passing them to the plugin in a `__testGlobs__` configuration option. With a small amount of
|
|
261
|
+
updates to the test files, they will continue to work long enough for you to rewrite them in a
|
|
262
|
+
more proper form. Read the configuration section for detail.
|
|
263
|
+
|
|
264
|
+
## Configuring the plugin
|
|
265
|
+
|
|
266
|
+
The Atlassian Web-Resource Webpack Plugin has a number of configuration options.
|
|
267
|
+
|
|
268
|
+
### `pluginKey` (Required)
|
|
269
|
+
|
|
270
|
+
The fully-qualified groupId and artifactId of your P2 plugin. Due to the way the WRM works, this
|
|
271
|
+
value is necessary to provide in order to support loading of asynchronous chunks, as well as arbirary
|
|
272
|
+
(non-JavaScript) resources.
|
|
273
|
+
|
|
274
|
+
### `xmlDescriptors` (Required)
|
|
275
|
+
|
|
276
|
+
An absolute filepath to where the generated XML should be output to. This should point to a sub-directory
|
|
277
|
+
of the Maven project's `${project.build.outputDirectory}` (which evaluates to `target/classes` in a
|
|
278
|
+
standard Maven project).
|
|
279
|
+
|
|
280
|
+
The sub-directory part of this configuration value needs to be configured in the project's `pom.xml`, as
|
|
281
|
+
demonstrated in the basic usage section above.
|
|
282
|
+
|
|
283
|
+
### `addEntrypointNameAsContext` (Optional)
|
|
284
|
+
|
|
285
|
+
When set to `true` (the default value), all generated web-resources will be added to
|
|
286
|
+
a context with the same name as the entrypoint.
|
|
287
|
+
|
|
288
|
+
This behaviour can be disabled by setting the value of this option to `false`.
|
|
289
|
+
|
|
290
|
+
### `addAsyncNameAsContext` (Optional)
|
|
291
|
+
|
|
292
|
+
When set to `true` (the default value), all generated web-resources for async chunks that have a name (specified via `webpackChunkName` on import) will be added to
|
|
293
|
+
a context of the name "async-chunk-<name as specified in webpackChunkName>".
|
|
294
|
+
|
|
295
|
+
This behaviour can be disabled by setting the value of this option to `false`.
|
|
296
|
+
|
|
297
|
+
### `contextMap` (Optional)
|
|
298
|
+
|
|
299
|
+
A set of key-value pairs that allows you to specify which webpack entry-points
|
|
300
|
+
should be present in what web-resource contexts at an Atlassian product runtime.
|
|
301
|
+
|
|
302
|
+
You can provide either a single web-resource context as a string, or an array of context strings.
|
|
303
|
+
|
|
304
|
+
### `conditionMap` (Optional)
|
|
305
|
+
|
|
306
|
+
An object specifying what conditions should be applied to a certain entry-point.
|
|
307
|
+
Simple example:
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"class": "foo.bar"
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
will yield:
|
|
315
|
+
```xml
|
|
316
|
+
<condition class="foo.bar" />
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Complex nested example with params:
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"conditionMap": {
|
|
323
|
+
"type": "AND",
|
|
324
|
+
"conditions": [
|
|
325
|
+
{
|
|
326
|
+
"type": "OR",
|
|
327
|
+
"conditions": [
|
|
328
|
+
{
|
|
329
|
+
"class": "foo.bar.baz",
|
|
330
|
+
"invert": true,
|
|
331
|
+
"params": [
|
|
332
|
+
{
|
|
333
|
+
"attributes": {
|
|
334
|
+
"name": "permission"
|
|
335
|
+
},
|
|
336
|
+
"value": "admin"
|
|
337
|
+
}
|
|
338
|
+
]
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
"class": "foo.bar.baz2",
|
|
342
|
+
"params": [
|
|
343
|
+
{
|
|
344
|
+
"attributes": {
|
|
345
|
+
"name": "permission"
|
|
346
|
+
},
|
|
347
|
+
"value": "project"
|
|
348
|
+
}
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
]
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
"class": "foo.bar.baz3",
|
|
355
|
+
"params": [
|
|
356
|
+
{
|
|
357
|
+
"attributes": {
|
|
358
|
+
"name": "permission"
|
|
359
|
+
},
|
|
360
|
+
"value": "admin"
|
|
361
|
+
}
|
|
362
|
+
]
|
|
363
|
+
}
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
will yield:
|
|
370
|
+
```xml
|
|
371
|
+
<conditions type="AND">
|
|
372
|
+
<conditions type="OR">
|
|
373
|
+
<condition class="foo.bar.baz" invert="true">
|
|
374
|
+
<param name="permission">admin</param>
|
|
375
|
+
</condition>
|
|
376
|
+
<condition class="foo.bar.baz2" >
|
|
377
|
+
<param name="permission">project</param>
|
|
378
|
+
</condition>
|
|
379
|
+
</conditions>
|
|
380
|
+
<condition class="foo.bar.baz3" >
|
|
381
|
+
<param name="permission">admin</param>
|
|
382
|
+
</condition>
|
|
383
|
+
</conditions>
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### `dataProvidersMap` (Optional)
|
|
387
|
+
|
|
388
|
+
The `dataProvidersMap` option allows configuring the association between entrypoint and a list of data providers.
|
|
389
|
+
|
|
390
|
+
Data providers can be used to provide a data from the server-side to the frontend, and claimed using `WRM.data.claim` API. To read more about data providers refer to [the official documentation](https://developer.atlassian.com/server/framework/atlassian-sdk/adding-data-providers-to-your-plugin/).
|
|
391
|
+
|
|
392
|
+
To associate the entrypoint with list of data providers you can configure the webpack configuration as follow:
|
|
393
|
+
|
|
394
|
+
```js
|
|
395
|
+
{
|
|
396
|
+
entrypoints: {
|
|
397
|
+
'my-first-entry-point': './first-entry-point.js',
|
|
398
|
+
'my-second-entry-point': './first-entry-point.js',
|
|
399
|
+
},
|
|
400
|
+
|
|
401
|
+
plugins: [
|
|
402
|
+
WrmPlugin({
|
|
403
|
+
pluginKey: 'my.full.plugin.artifact-id',
|
|
404
|
+
dataProvidersMap: {
|
|
405
|
+
'my-first-entry-point': [
|
|
406
|
+
{
|
|
407
|
+
key: 'my-foo-data-provider',
|
|
408
|
+
class: 'com.example.myplugin.FooDataProvider'
|
|
409
|
+
}
|
|
410
|
+
],
|
|
411
|
+
|
|
412
|
+
'my-second-entry-point': [
|
|
413
|
+
{
|
|
414
|
+
key: 'my-bar-data-provider',
|
|
415
|
+
class: 'com.example.myplugin.BarDataProvider'
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
{
|
|
419
|
+
key: 'my-bizbaz-data-provider',
|
|
420
|
+
class: 'com.example.myplugin.BizBazDataProvider'
|
|
421
|
+
}
|
|
422
|
+
],
|
|
423
|
+
}
|
|
424
|
+
})
|
|
425
|
+
]
|
|
426
|
+
}
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
will yield:
|
|
430
|
+
```xml
|
|
431
|
+
<web-resource key="<<key-of-my-first-entry-point>>">
|
|
432
|
+
<resource ... />
|
|
433
|
+
<resource ... />
|
|
434
|
+
|
|
435
|
+
<data key="my-foo-data-provider" class="com.example.myplugin.FooDataProvider" />
|
|
436
|
+
</web-resource>
|
|
437
|
+
|
|
438
|
+
<web-resource key="<<key-of-my-first-entry-point>>">
|
|
439
|
+
<resource ... />
|
|
440
|
+
<resource ... />
|
|
441
|
+
|
|
442
|
+
<data key="my-bar-data-provider" class="com.example.myplugin.BarDataProvider" />
|
|
443
|
+
<data key="my-bizbaz-data-provider" class="com.example.myplugin.BizBazDataProvider" />
|
|
444
|
+
</web-resource>
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### `transformationMap` (Optional)
|
|
448
|
+
|
|
449
|
+
An object specifying transformations to be applied to file types.
|
|
450
|
+
The default transformations are:
|
|
451
|
+
|
|
452
|
+
- `*.js` files => `jsI18n`
|
|
453
|
+
- `*.soy` files => `soyTransformer`, `jsI18n`
|
|
454
|
+
- `*.less` files => `lessTransformer`
|
|
455
|
+
|
|
456
|
+
Example configuration for custom transformations:
|
|
457
|
+
|
|
458
|
+
```json
|
|
459
|
+
{
|
|
460
|
+
"transformationMap": {
|
|
461
|
+
"js": ["myOwnJsTransformer"],
|
|
462
|
+
"sass": ["myOwnSassTransformer"]
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
This would set the following transformations to every generated web-resource:
|
|
468
|
+
|
|
469
|
+
```xml
|
|
470
|
+
<transformation extension="js">
|
|
471
|
+
<transformer key="myOwnJsTransformer"/>
|
|
472
|
+
</transformation>
|
|
473
|
+
<transformation extension="sass">
|
|
474
|
+
<transformer key="myOwnSassTransformer"/>
|
|
475
|
+
</transformation>
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
If you wish to extend the default transformations you can use the build-in `extendTransformations` function provided by the plugin.
|
|
479
|
+
It will merge the default transformations with your custom config:
|
|
480
|
+
|
|
481
|
+
```js
|
|
482
|
+
const WrmPlugin = require('atlassian-webresource-webpack-plugin');
|
|
483
|
+
|
|
484
|
+
new WrmPlugin({
|
|
485
|
+
pluginKey: 'my.full.plugin.artifact-id',
|
|
486
|
+
transformationMap: WrmPlugin.extendTransformations({
|
|
487
|
+
js: ['myOwnJsTransformer'],
|
|
488
|
+
sass: ['myOwnSassTransformer'],
|
|
489
|
+
}),
|
|
490
|
+
});
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
You can also completely disable the transformations by passing `false` value to the plugin configuration:
|
|
494
|
+
|
|
495
|
+
```json
|
|
496
|
+
{
|
|
497
|
+
"transformationMap": false
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
### `webresourceKeyMap` (Optional)
|
|
502
|
+
|
|
503
|
+
Allows you to change the name of the web-resource that is generated for a given webpack entry-point.
|
|
504
|
+
|
|
505
|
+
This is useful when you expect other plugins will need to depend on your auto-generated web-resources directly, such
|
|
506
|
+
as when you refactor an existing feature (and its web-resource) to be generated via Webpack.
|
|
507
|
+
|
|
508
|
+
This parameter can take either `string` or `object` with properties `key`, `name` and `state` which corresponds to
|
|
509
|
+
`key`, `name` and `state` attributes of `web-resource` XML element. `name` and `state` properties are optional.
|
|
510
|
+
|
|
511
|
+
Mapping as follows:
|
|
512
|
+
```json
|
|
513
|
+
{
|
|
514
|
+
"webresourceKeyMap": {
|
|
515
|
+
"firstWebResource": "first-web-resource",
|
|
516
|
+
"secondWebResource": {
|
|
517
|
+
"key": "second-web-resource",
|
|
518
|
+
"name": "Second WebResource",
|
|
519
|
+
"state": "disabled"
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
will result in the following web-resources:
|
|
526
|
+
```xml
|
|
527
|
+
<web-resource key="first-web-resource" name="" state="enabled">
|
|
528
|
+
<!-- your resources definitions -->
|
|
529
|
+
</web-resource>
|
|
530
|
+
<web-resource key="second-web-resource" name="Second WebResource" state="disabled">
|
|
531
|
+
<!-- your resources definitions -->
|
|
532
|
+
</web-resource>
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### `providedDependencies` (Optional)
|
|
536
|
+
|
|
537
|
+
A map of objects that let you associate what web-resources house particular external JS dependencies.
|
|
538
|
+
|
|
539
|
+
The format of an external dependency mapping is as follows:
|
|
540
|
+
|
|
541
|
+
```json
|
|
542
|
+
{
|
|
543
|
+
"dependency-name": {
|
|
544
|
+
"dependency": "atlassian.plugin.key:webresource-key",
|
|
545
|
+
"import": externals
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
In this example, `externals` is a JSON object following the
|
|
551
|
+
[Webpack externals format][webpack-externalobjects].
|
|
552
|
+
|
|
553
|
+
When your code is compiled through webpack, any occurrence of `dependency-name` found in a module import
|
|
554
|
+
statement will be replaced in the webpack output, and an appropriate web-resource `<dependency>` will be
|
|
555
|
+
added to the generated web-resource.
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
### `wrmManifestPath` (Optional)
|
|
559
|
+
|
|
560
|
+
A path to a WRM manifest file where the plugin will store a map of objects.
|
|
561
|
+
Under the `providedDependencies` property is a map of dependencies, including the generated web-resource keys.
|
|
562
|
+
This map is the exact same format that is accepted with the `providedDependencies` option above,
|
|
563
|
+
so one can use this map as a source for `providedDependencies` in another build:
|
|
564
|
+
|
|
565
|
+
```json
|
|
566
|
+
{
|
|
567
|
+
"providedDependencies": {
|
|
568
|
+
"dependency-name": {
|
|
569
|
+
"dependency": "atlassian.plugin.key:webresource-key",
|
|
570
|
+
"import": {
|
|
571
|
+
"var": "require('dependency-amd-module-name')",
|
|
572
|
+
"amd": "dependency-amd-module-name"
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
#### Notes and limitations
|
|
580
|
+
|
|
581
|
+
* Both `output.library` and `output.libraryTarget` must be set for the WRM manifest file to be created.
|
|
582
|
+
* `output.library` must not contain \[chunk\] or \[hash\], however \[name\] is allowed
|
|
583
|
+
* `output.libraryTarget` must be set to `amd`
|
|
584
|
+
* More properties might be added to the WRM manifest file in future
|
|
585
|
+
|
|
586
|
+
#### Example configuration
|
|
587
|
+
|
|
588
|
+
```json
|
|
589
|
+
{
|
|
590
|
+
"output": {
|
|
591
|
+
"library": "[name]",
|
|
592
|
+
"libraryTarget": "amd"
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
### `resourceParamMap` (Optional)
|
|
598
|
+
|
|
599
|
+
An object specifying additional parameters (`<param/>`) for `resource`s.
|
|
600
|
+
|
|
601
|
+
To specify for example content-types the server should respond with for a certain assets file-type (e.g. images/fonts):
|
|
602
|
+
|
|
603
|
+
```json
|
|
604
|
+
{
|
|
605
|
+
"resourceParamMap": {
|
|
606
|
+
"svg": [{
|
|
607
|
+
"name": "content-type",
|
|
608
|
+
"value": "image/svg+xml"
|
|
609
|
+
}]
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
Setting specific content-types may be required by certain Atlassian products depending on the file-type to load.
|
|
615
|
+
*Contains content-type for svg as "image/svg+xml" by default*
|
|
616
|
+
|
|
617
|
+
### `locationPrefix` (Optional)
|
|
618
|
+
|
|
619
|
+
Adds given prefix value to `location` attribute of `resource` node.
|
|
620
|
+
Use this option when your webpack output is placed in a subdirectory of the plugin's ultimate root folder.
|
|
621
|
+
|
|
622
|
+
### `devAssetsHash` (Optional)
|
|
623
|
+
Uses provided value (instead of DEV_PSEUDO_HASH) in the webresource name that contains all of the assets needed in development mode.
|
|
624
|
+
|
|
625
|
+
### `watch` and `watchPrepare` (Optional)
|
|
626
|
+
Activates "watch-mode". This must be run in conjuction with a webpack-dev-server.
|
|
627
|
+
#### `watchPrepare`
|
|
628
|
+
Creates "proxy"-Resources and references them in the XML-descriptor. These proxy-resources will redirect to a webpack-dev-server that has to be run too.
|
|
629
|
+
In order for this to work properly, ensure that the webpack-config "options.output.publicPath" points to the webpack-dev-server - including its port. (e.g. http://localhost:9000)
|
|
630
|
+
#### `watch` (Optional)
|
|
631
|
+
Use when running the process with a webpack-dev-server.
|
|
632
|
+
|
|
633
|
+
### `useDocumentWriteInWatchMode` (Optional)
|
|
634
|
+
When set to `true`, the generated watch mode modules will add the script tags to the document synchronously with `document.write` while the document is loading, rather than always relying on asynchronously appended script tags (default behaviour).
|
|
635
|
+
|
|
636
|
+
This is useful when bundles are expected to be available on the page early, e.g. when code in a template relies on javascript to be loaded blockingly.
|
|
637
|
+
|
|
638
|
+
### `noWRM` (Optional)
|
|
639
|
+
Will not add any WRM-specifics to the webpack-runtime or try to redirect async-chunk requests while still handling requests to `wr-dependency` and `wr-resource`.
|
|
640
|
+
This can be useful to develop frontend outside of a running product that provides the WRM functionality.
|
|
641
|
+
|
|
642
|
+
### `singleRuntimeWebResourceKey` (Optional)
|
|
643
|
+
Set a specific web-resource key for the Webpack runtime when using the Webpack option `optimization.runtimeChunk` to `single` (see [runtimeChunk documentation](https://webpack.js.org/configuration/optimization/#optimizationruntimechunk)). Default is `common-runtime`.
|
|
644
|
+
|
|
645
|
+
### `verbose` (Optional)
|
|
646
|
+
Indicate verbosity of log output. Default is `false`.
|
|
647
|
+
|
|
648
|
+
### `standalone` (Optional) (Experimental)
|
|
649
|
+
**Do not use this**
|
|
650
|
+
Builds standalone web-resources, no transformations and base-dependencies will be applied.
|
|
651
|
+
No non-entry-chunks are supported.
|
|
652
|
+
*Experimental - may change or be removed again at any time*
|
|
653
|
+
|
|
654
|
+
## Deprecated configuration
|
|
655
|
+
|
|
656
|
+
### `assetContentTypes` (DEPRECATED) (Optional)
|
|
657
|
+
|
|
658
|
+
> This option is **deprecated** and will be removed in a future version. Please use `resourceParamMap` instead.
|
|
659
|
+
|
|
660
|
+
An object specifying content-types the server should respond with for a certain assets file-type (e.g. images/fonts):
|
|
661
|
+
|
|
662
|
+
```json
|
|
663
|
+
{
|
|
664
|
+
"assetContentTypes": {
|
|
665
|
+
"svg": "image/svg+xml"
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
This may be required by certain Atlassian products depending on the file-type to load.
|
|
671
|
+
*Contains content-type for svg as "image/svg+xml" by default*
|
|
672
|
+
|
|
673
|
+
### `__testGlobs__` (Optional) (Deprecated)
|
|
674
|
+
|
|
675
|
+
When provided, the Webpack compilation will generate `<resource type="qunit"/>` entries for each test file
|
|
676
|
+
the glob specifies. It will also cause Webpack to generate web-resources for both the compiled output *and*
|
|
677
|
+
raw source modules.
|
|
678
|
+
|
|
679
|
+
The source modules will be available in a web-resource key beginning with `__test__`, followed by the name
|
|
680
|
+
of the entrypoint they were discovered through. For instance, if your entrypoint name is `my-feature`,
|
|
681
|
+
and your plugin key is `com.example.myplugin`, the web-resource key for `my-feature`'s source modules will be
|
|
682
|
+
`com.example.myplugin:__test__entrypoint-my-feature`.
|
|
683
|
+
|
|
684
|
+
Because the web-resource name with testable source files is auto-generated, the QUnit test files will
|
|
685
|
+
need to be updated to point at the appropriate web-resource key,
|
|
686
|
+
so that any modules the test expects to be present will be loaded via the WRM at runtime.
|
|
687
|
+
|
|
688
|
+
This configuration option is deprecated and will be removed in a 1.0 release of this plugin. The option
|
|
689
|
+
exists to give developers time to refactor and rewrite their QUnit tests as build-time tests; either
|
|
690
|
+
as pure unit tests (e.g., via Jest or Mocha) or pure black-box integration tests (e.g., via Webdriver).
|
|
691
|
+
|
|
692
|
+
## Minimum requirements
|
|
693
|
+
|
|
694
|
+
This plugin has been built to work with the following versions of the external build tools:
|
|
695
|
+
|
|
696
|
+
* Webpack 4+
|
|
697
|
+
* Node 6+ (at P2 plugin build-time)
|
|
698
|
+
* [Atlassian Maven Plugin Suite (AMPS)][atlassian-amps] 6.2.11+
|
|
699
|
+
* [Atlassian Web Resource Manager (WRM)][atlassian-wrm] 3.6+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
[101]: https://bitbucket.org/serverecosystem/sao4fed-bundle-the-ui
|
|
703
|
+
[104]: https://bitbucket.org/atlassian/atlassian-qunit-plugin
|
|
704
|
+
[atlassian-sdk]: https://developer.atlassian.com/server/framework/atlassian-sdk
|
|
705
|
+
[atlassian-amps]: https://developer.atlassian.com/server/framework/atlassian-sdk/working-with-maven/#using-the-amps-maven-plugin-directly
|
|
706
|
+
[atlassian-p2]: https://bitbucket.org/atlassian/atlassian-plugins
|
|
707
|
+
[atlassian-wrm]: https://bitbucket.org/atlassian/atlassian-plugins-webresource
|
|
708
|
+
[webpack]: https://webpack.js.org/
|
|
709
|
+
[webpack-externalobjects]: https://webpack.js.org/configuration/externals/#object
|