Skip to content

fix(bundling): Publish the unminified UMD bundle along with the minified one #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 14, 2018

Conversation

mikeproeng37
Copy link
Contributor

@mikeproeng37 mikeproeng37 commented Nov 14, 2018

Summary

  • We need to build and publish the unminified bundle to NPM as we publicly refer to it in our docs.

This is the output of cleaning the local /dist directory and building manually with npm run build-browser-umd:

Hash: 1e3850c525529035af49
Version: webpack 2.7.0
Time: 1222ms
                        Asset     Size  Chunks             Chunk Names
optimizely.browser.umd.min.js  82.8 kB       0  [emitted]  main
   [1] ./lib/utils/enums/index.js 11.8 kB {0} [built]
   [3] ./~/sprintf-js/src/sprintf.js 8.67 kB {0} [built]
   [4] ./lib/utils/fns/index.js 1.21 kB {0} [built]
  [44] ./lib/utils/config_validator/index.js 2.95 kB {0} [built]
  [74] ./lib/optimizely/index.js 28.7 kB {0} [built]
  [75] ./lib/plugins/error_handler/index.js 809 bytes {0} [built]
  [76] ./lib/plugins/event_dispatcher/index.browser.js 2.42 kB {0} [built]
  [77] ./lib/plugins/logger/index.js 4.09 kB {0} [built]
  [84] ./lib/index.browser.js 2.78 kB {0} [built]
  [85] ./lib/optimizely/project_config_schema.js 7.02 kB {0} [built]
  [87] ./lib/utils/event_tags_validator/index.js 1.29 kB {0} [built]
  [88] ./lib/utils/string_value_validator/index.js 864 bytes {0} [built]
  [89] ./lib/utils/user_profile_service_validator/index.js 2.14 kB {0} [built]
 [190] ./~/lodash/forEach.js 1.35 kB {0} [built]
 [193] ./~/lodash/isEmpty.js 2 kB {0} [built]
    + 194 hidden modules
Hash: 41332d833233093fb3ac
Version: webpack 2.7.0
Time: 458ms
                    Asset    Size  Chunks                    Chunk Names
optimizely.browser.umd.js  319 kB       0  [emitted]  [big]  main
   [1] ./lib/utils/enums/index.js 11.8 kB {0} [built]
   [3] ./~/sprintf-js/src/sprintf.js 8.67 kB {0} [built]
   [4] ./lib/utils/fns/index.js 1.21 kB {0} [built]
  [44] ./lib/utils/config_validator/index.js 2.95 kB {0} [built]
  [74] ./lib/optimizely/index.js 28.7 kB {0} [built]
  [75] ./lib/plugins/error_handler/index.js 809 bytes {0} [built]
  [76] ./lib/plugins/event_dispatcher/index.browser.js 2.42 kB {0} [built]
  [77] ./lib/plugins/logger/index.js 4.09 kB {0} [built]
  [84] ./lib/index.browser.js 2.78 kB {0} [built]
  [85] ./lib/optimizely/project_config_schema.js 7.02 kB {0} [built]
  [87] ./lib/utils/event_tags_validator/index.js 1.29 kB {0} [built]
  [88] ./lib/utils/string_value_validator/index.js 864 bytes {0} [built]
  [89] ./lib/utils/user_profile_service_validator/index.js 2.14 kB {0} [built]
 [190] ./~/lodash/forEach.js 1.35 kB {0} [built]
 [193] ./~/lodash/isEmpty.js 2 kB {0} [built]
    + 194 hidden modules
total 792
-rw-r--r--  1 mng  staff  319465 Nov 14 13:49 optimizely.browser.umd.js
-rw-r--r--  1 mng  staff   83743 Nov 14 13:49 optimizely.browser.umd.min.js

Testing

  • Manually loaded both min and unminified files in the browser and verified that window.optimizelySdk and window.optimizelyClient are accessible.

@@ -36,6 +36,9 @@ The package's entry point is a CommonJS module, which can be used directly in en

```html
<script src="https://unpkg.com/@optimizely/optimizely-sdk/dist/optimizely.browser.umd.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this? There is no reason for anyone to ever use the unminified version this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this has actually been requested before: #57

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least, we should lead with the minified version

@@ -26,3 +26,28 @@ Object.defineProperty(window, 'optimizelyClient', {
});
EOF

# Builds the unminified bundle
npx webpack lib/index.browser.js dist/optimizely.browser.umd.js \
--define process.env.NODE_ENV="production" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be "development"? I don't get how "production" would produce an unminified bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minification is specified with a different flag: --optimize-minimize. I still think this should be a prod, yet unminified bundle since it might be used in production

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikeng13 explained: -p is equivalent to this config plus --optimize-minimize, so this is just ensuring that only the --optimize-minimize part is skipped.

@tylerbrandt
Copy link
Contributor

Can you include the output of this command in the PR summary?

rm -rf dist && npm run build-browser-umd && ls -l dist

--output-library="$BUNDLE_NAME"

# Append some backwards-compatibility code to the bundle
cat - >> dist/optimizely.browser.umd.min.js <<EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be .umd.js right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah thanks for catching

@mikeproeng37 mikeproeng37 changed the title fix(bundling): Publish the unminified UMDbundle along with the minified one fix(bundling): Publish the unminified UMD bundle along with the minified one Nov 14, 2018
Copy link
Contributor

@tylerbrandt tylerbrandt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update CHANGELOG (unreleased section) and we should be good to go

@@ -36,6 +36,9 @@ The package's entry point is a CommonJS module, which can be used directly in en

```html
<script src="https://unpkg.com/@optimizely/optimizely-sdk/dist/optimizely.browser.umd.js"></script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least, we should lead with the minified version

@tylerbrandt
Copy link
Contributor

:shipit:

@mikeproeng37 mikeproeng37 merged commit 240f7ed into 2.3.x Nov 14, 2018
tylerbrandt pushed a commit that referenced this pull request Nov 15, 2018
## Summary

**BREAKING**: Drop support for `window.optimizelyClient`, as presaged in the [CHANGELOG](https://github.com/optimizely/javascript-sdk/blob/master/packages/optimizely-sdk/CHANGELOG.MD#213---august-21-2018).

- Pull in changes from 2.3.x, to ensure that both optimizely.browser.umd.js and optimizely.browser.umd.min.js are defined.
- Refactor those changes to use webpack config/index.browser code instead of appending to the bundle after-the-fact.
- Actually install `webpack` as a devDependency rather than always using latest

In addition to fixing the issue from #187 in this branch, it simplifies the build script.

## Test plan

Existing unit tests pass since the "node" API for index.browser.js wasn't changed.

Created a test file called "dist/test.html" and loaded it in a browser (as well as an equivalent one that loads the min.js variant):
```html
<!DOCTYPE html>
<html>

<head>
	<script src="/optimizely.browser.umd.js"></script>
</head>

<body>
	<h1>Hello</h1>
	<script>
		console.log('optimizelySdk', typeof optimizelySdk);
		console.log('optimizelyClient', typeof optimizelyClient);
	</script>
</body>

</html>
```
Ensured that it logged "object" for the first, and "undefined" for the second:
![screen shot 2018-11-14 at 3 50 30 pm](https://user-images.githubusercontent.com/1256483/48520564-ecdadb00-e825-11e8-8d97-18c8fe27985c.png)

## Issues
- OASIS-3790
@mikeproeng37 mikeproeng37 deleted the mng/fix-umd-bundle branch December 14, 2018 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants