Skip to content

Commit db84457

Browse files
committed
create a bundled snippet build
1 parent 712f965 commit db84457

6 files changed

+48
-2
lines changed

build.sh

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fi
99

1010
echo 'Building main bundles'
1111
npx rollup -i src/loaders/loader-globals.js -f iife -o build/mixpanel.globals.js -n mixpanel -c rollup.config.js
12+
USE_BABEL=true npx rollup -i src/loaders/loader-globals-with-recorder.js -f iife -o build/mixpanel-with-recorder.js -n mixpanel -c rollup.config.js
1213
npx rollup -i src/recorder/index.js -f iife -n mixpanel -c src/recorder/rollup.config.js
1314
ln -sf mixpanel.globals.js build/mixpanel.js
1415

@@ -17,6 +18,9 @@ if [ ! -z "$FULL" ]; then
1718
java -jar vendor/closure-compiler/compiler.jar --js build/mixpanel.js --language_in ECMASCRIPT5 --externs src/externs.js --js_output_file build/mixpanel.min.js --compilation_level ADVANCED_OPTIMIZATIONS --output_wrapper "(function() {
1819
%output%
1920
})();"
21+
# we use esbuild to minify the recorder because that's what rrweb uses
22+
USE_BABEL=true USE_ESBUILD=true npx rollup -i src/loaders/loader-globals-with-recorder.js -f iife -o build/mixpanel-with-recorder.min.js -n mixpanel -c rollup.config.js
23+
2024
java -jar vendor/closure-compiler/compiler.jar --js src/loaders/mixpanel-jslib-snippet.js --language_in ECMASCRIPT5 --js_output_file build/mixpanel-jslib-snippet.min.js --compilation_level ADVANCED_OPTIMIZATIONS
2125
java -jar vendor/closure-compiler/compiler.jar --js src/loaders/mixpanel-jslib-snippet.js --language_in ECMASCRIPT5 --js_output_file build/mixpanel-jslib-snippet.min.test.js --compilation_level ADVANCED_OPTIMIZATIONS --define='MIXPANEL_LIB_URL="../build/mixpanel.min.js"'
2226

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rollup.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import nodeResolve from '@rollup/plugin-node-resolve';
2+
import esbuild from 'rollup-plugin-esbuild';
23
import babel from '@rollup/plugin-babel';
34

45
const useBabel = process.env.USE_BABEL === 'true';
6+
const useESBuild = process.env.USE_ESBUILD === 'true';
57

68
export default {
79
plugins: [
@@ -11,5 +13,6 @@ export default {
1113
jsnext: true,
1214
}),
1315
...(useBabel ? [babel({ babelHelpers: 'bundled', presets: ['@babel/preset-env'] })] : []),
16+
...(useESBuild ? [esbuild({ minify: true, sourceMap: true })] : [])
1417
]
1518
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* eslint camelcase: "off" */
2+
import '../recorder';
3+
4+
import { init_from_snippet } from '../mixpanel-core';
5+
import { loadNoop } from './bundle-loaders';
6+
7+
init_from_snippet(loadNoop);

tests/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ <h2>Base tests</h2>
77
<ul>
88
<li><a href="tests.html">Dev (unminified)</a></li>
99
<li><a href="tests_min.html">Production (minified)</a></li>
10+
<li><a href="tests_min_bundled_recorder.html">Production + bundled recorder (minified)</a></li>
1011
</ul>
1112

1213
<h2>Other implementation scenarios</h2>

tests/tests_min_bundled_recorder.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen">
5+
<script type="text/javascript" src="vendor/core-js-polyfills.js"></script>
6+
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
7+
<script type="text/javascript" src="vendor/jquery.qunit.js?v=159"></script>
8+
<script type="text/javascript" src="../node_modules/sinon/pkg/sinon.js"></script>
9+
<script type="text/javascript" src="vendor/underscore.js"></script>
10+
<script type="text/javascript" src="test.js"></script>
11+
<link rel="stylesheet" type="text/css" href="tests.css">
12+
</head>
13+
<body>
14+
<h1 id="qunit-header">lib 2.2 <a id="other-test" href="/tests/">other tests</a></h1>
15+
<h2 id="qunit-banner"></h2>
16+
<div id="qunit-testrunner-toolbar"></div>
17+
<h2 id="qunit-userAgent"></h2>
18+
<ol id="qunit-tests"></ol>
19+
<div id="qunit-fixture">
20+
<svg class="svg-class" width="22.314" height="18.261" viewBox="0 0 22.314 18.261" version="1.1">
21+
<path d="M21.314,2H1C0.448,2,0,1.552,0,1s0.448-1,1-1h20.314c0.552,0,1,0.448,1,1S21.867,2,21.314,2z"></path>
22+
<path d="M21.314,10.13H1c-0.552,0-1-0.448-1-1s0.448-1,1-1h20.314c0.552,0,1,0.448,1,1S21.867,10.13,21.314,10.13z"></path>
23+
<path d="M21.314,18.261H1c-0.552,0-1-0.448-1-1s0.448-1,1-1h20.314c0.552,0,1,0.448,1,1S21.867,18.261,21.314,18.261z"></path>
24+
</svg>
25+
</div>
26+
<script>window.MIXPANEL_CUSTOM_LIB_URL = '../build/mixpanel-with-recorder.min.js';</script>
27+
<script type="text/javascript" src="redirect-unless-referrer.js"></script>
28+
<script type="text/javascript" src="../build/mixpanel-jslib-snippet.min.test.js"></script>
29+
<script type="text/javascript" src="./run-tests.js"></script>
30+
</body>
31+
</html>

0 commit comments

Comments
 (0)