-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
@@ -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> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" \ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Can you include the output of this command in the PR summary?
|
--output-library="$BUNDLE_NAME" | ||
|
||
# Append some backwards-compatibility code to the bundle | ||
cat - >> dist/optimizely.browser.umd.min.js <<EOF |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this 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> |
There was a problem hiding this comment.
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
|
## 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:  ## Issues - OASIS-3790
Summary
This is the output of cleaning the local
/dist
directory and building manually withnpm run build-browser-umd
:Testing
window.optimizelySdk
andwindow.optimizelyClient
are accessible.