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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/optimizely-sdk/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
Changes that have landed but are not yet released.
- fix(bundling): Publish the unminified UMD bundle along with the minified one.

## [2.3.0] - November 14, 2018

### New Features
Expand Down
3 changes: 3 additions & 0 deletions packages/optimizely-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


<!-- You can also use the minified version instead -->
<script src="https://unpkg.com/@optimizely/optimizely-sdk/dist/optimizely.browser.umd.min.js"></script>
```

When evaluated, that bundle assigns the SDK's exports to `window.optimizelySdk`. If you wish to use the asset locally (for example, if unpkg is down), you can find it in your local copy of the package at dist/optimizely.browser.umd.min.js.
Expand Down
25 changes: 25 additions & 0 deletions packages/optimizely-sdk/scripts/build_browser_umd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.

--output-library-target=umd \
--output-library="$BUNDLE_NAME"

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


window._optimizelyClientWarningGiven = false;

Object.defineProperty(window, 'optimizelyClient', {
get: function () {
if (!window._optimizelyClientWarningGiven) {
console.warn('Accessing the SDK via window.optimizelyClient is deprecated; please use window.optimizelySdk instead. This alias will be dropped in 3.0.0.');
window._optimizelyClientWarningGiven = true;
}

return {
createInstance: window.optimizelySdk.createInstance
};
}
});
EOF