Skip to content

Commit

Permalink
Use an iife bundle for the snippet (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krishna Rajendran authored Apr 13, 2020
1 parent f2025ee commit 34d978f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ $(OUT): node_modules $(SRC) package.json rollup.config.js rollup.min.js rollup.n
@$(JSHINT) --verbose $(SRC)
@NODE_ENV=production $(ROLLUP) --config rollup.config.js
@NODE_ENV=production $(ROLLUP) --config rollup.esm.js
@NODE_ENV=production $(ROLLUP) --config rollup.umd.js
@NODE_ENV=production $(ROLLUP) --config rollup.native.js
@NODE_ENV=production $(ROLLUP) --config rollup.nocompat.js
@NODE_ENV=production $(ROLLUP) --config rollup.min.js
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "amplitude-js",
"description": "Javascript library for Amplitude Analytics",
"main": "amplitude.js",
"main": "amplitude.umd.js",
"authors": [
"Amplitude <[email protected]>"
],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "amplitude-js",
"author": "Amplitude <[email protected]>",
"version": "5.11.0",
"version": "5.12.0",
"license": "MIT",
"description": "Javascript library for Amplitude Analytics",
"keywords": [
"analytics",
"amplitude"
],
"repository": "git://github.com/amplitude/amplitude-javascript.git",
"main": "amplitude.js",
"main": "amplitude.umd.js",
"react-native": "amplitude.native.js",
"dependencies": {
"@amplitude/ua-parser-js": "0.7.20",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
output: {
name: 'amplitude',
file: 'amplitude.js',
format: 'umd',
format: 'iife',
amd: {
id: 'amplitude',
}
Expand Down
34 changes: 34 additions & 0 deletions rollup.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';

export default {
input: 'src/index.js',
output: {
name: 'amplitude',
file: 'amplitude.js',
format: 'umd',
amd: {
id: 'amplitude',
}
},
plugins: [
json(),
babel({
exclude: 'node_modules/**',
plugins: ['@babel/plugin-proposal-object-rest-spread'],
}),
resolve({
browser: true,
}),
replace({
BUILD_COMPAT_SNIPPET: 'true',
BUILD_COMPAT_LOCAL_STORAGE: 'true',
BUILD_COMPAT_2_0: 'true',
BUILD_COMPAT_REACT_NATIVE: 'false',
}),
commonjs(),
],
};
4 changes: 2 additions & 2 deletions src/amplitude-snippet.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
var amplitude = window.amplitude || {'_q':[],'_iq':{}};
var as = document.createElement('script');
as.type = 'text/javascript';
as.integrity = 'sha384-XjqOOyFvYU+vG4+WrAuiEGo7iwlPziIAukUSiFSme/Jj5Rdk1G9Fu5iMmjxg4XRk';
as.integrity = 'sha384-AGAP8hLFGmWct8CISyv9W0dsAYlj/1X7y99zLRAMPI8HANfyBrMgg8CMmBs+jPsZ';
as.crossOrigin = 'anonymous';
as.async = true;
as.src = 'https://cdn.amplitude.com/libs/amplitude-5.11.0-min.gz.js';
as.src = 'https://cdn.amplitude.com/libs/amplitude-5.12.0-min.gz.js';
as.onload = function() {if(!window.amplitude.runQueuedFunctions) {console.log('[Amplitude] Error: could not load SDK');}};
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(as, s);
Expand Down

0 comments on commit 34d978f

Please sign in to comment.