Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 8c8abab

Browse files
committed
revert to master
1 parent dd1f581 commit 8c8abab

File tree

2 files changed

+38
-117
lines changed

2 files changed

+38
-117
lines changed

packages/optimizely-sdk/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"access": "public"
77
},
88
"description": "JavaScript SDK for Optimizely X Full Stack",
9+
"module": "dist/optimizely.browser.es.min.js",
910
"main": "dist/optimizely.node.min.js",
10-
"module": "dist/optimizely.browser.es.js",
1111
"browser": "dist/optimizely.browser.min.js",
1212
"react-native": "dist/optimizely.react_native.min.js",
1313
"typings": "lib/index.d.ts",
1414
"scripts": {
1515
"test": "mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js --recursive --exit --require esm --require lib/tests/exit_on_unhandled_rejection.js",
1616
"test-xbrowser": "karma start karma.bs.conf.js --single-run",
1717
"test-umdbrowser": "npm run build-browser-umd && karma start karma.umd.conf.js --single-run",
18-
"build-browser-umd": "rollup -c --config-umd",
19-
"build": "rm -rf dist && rollup -c",
18+
"build-browser-umd": "rollup -c --environment BUILD_UMD_BUNDLE",
19+
"build": "rm -rf dist && rollup -c --environment BUILD_ALL",
2020
"test-ci": "npm run test-xbrowser && npm run test-umdbrowser",
2121
"lint": "eslint 'lib/**/*.js'",
2222
"cover": "istanbul cover _mocha ./lib/*.tests.js ./lib/**/*.tests.js ./lib/**/**/*tests.js",

packages/optimizely-sdk/rollup.config.js

Lines changed: 35 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -13,99 +13,44 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
17-
import path from 'path';
18-
import alias from '@rollup/plugin-alias';
16+
import { dependencies } from './package.json';
1917
import commonjs from '@rollup/plugin-commonjs';
2018
import { terser } from 'rollup-plugin-terser';
2119
import resolve from '@rollup/plugin-node-resolve';
22-
import visualizer from 'rollup-plugin-visualizer';
23-
import { dependencies } from './package.json';
2420

25-
const cjsBuildFor = (platform) => ({
26-
plugins: [
27-
resolve(),
28-
commonjs(),
29-
],
30-
external: ['https', 'http', 'url'].concat(Object.keys(dependencies || {})),
31-
input: `lib/index.${platform}.js`,
21+
const BUILD_ALL = process.env.BUILD_ALL ? true : false;
22+
const BUILD_UMD_BUNDLE = process.env.BUILD_UMD_BUNDLE ? true : false;
23+
24+
const getCjsConfigForPlatform = (platform) => {
25+
return {
26+
plugins: [
27+
resolve(),
28+
commonjs(),
29+
],
30+
external: ['https', 'http', 'url'].concat(Object.keys(dependencies || {})),
31+
input: `lib/index.${platform}.js`,
32+
output: {
33+
exports: 'named',
34+
format: 'cjs',
35+
file: `dist/optimizely.${platform}.min.js`,
36+
plugins: [ terser() ],
37+
sourcemap: true,
38+
}
39+
};
40+
};
41+
42+
const esModuleConfig = {
43+
... getCjsConfigForPlatform('browser'),
3244
output: {
3345
exports: 'named',
34-
format: 'cjs',
35-
file: `dist/optimizely.${platform}.min.js`,
36-
plugins: [ terser() ],
37-
sourcemap: true,
38-
}
39-
});
40-
41-
const esmBundle = {
42-
...cjsBuildFor('browser'),
43-
output: [{
44-
format: 'es',
45-
file: 'dist/optimizely.browser.es.js',
46-
sourcemap: true,
47-
}, {
4846
format: 'es',
4947
file: 'dist/optimizely.browser.es.min.js',
50-
sourcemap: true,
5148
plugins: [ terser() ],
5249
sourcemap: true,
53-
}]
54-
}
55-
56-
// ESM Bundle for browsers with all optimizely deps included
57-
const esmFullBundle = {
58-
input: 'lib/index.browser.js',
59-
external: ['https', 'http', 'url'],
60-
plugins: [
61-
resolve({browser: true}),
62-
commonjs({
63-
namedExports: {
64-
'@optimizely/js-sdk-logging': [
65-
'ConsoleLogHandler',
66-
'getLogger',
67-
'setLogLevel',
68-
'LogLevel',
69-
'setLogHandler',
70-
'setErrorHandler',
71-
'getErrorHandler',
72-
],
73-
'@optimizely/js-sdk-event-processor': [
74-
'LogTierV1EventProcessor',
75-
'LocalStoragePendingEventsDispatcher',
76-
]
77-
}
78-
}),
79-
],
80-
output: {
81-
format: 'es',
82-
file: 'dist/optimizely.browser.es.full.js',
83-
sourcemap: true,
84-
},
85-
}
86-
87-
const esmSlimBundle = {
88-
...esmFullBundle,
89-
plugins: [
90-
alias({ entries: [
91-
{ find: './project_config_schema',
92-
replacement: path.resolve(__dirname, 'ext/project_config_schema.json') },
93-
{ find: path.resolve(__dirname, 'lib/utils/config_validator/index.js'),
94-
replacement: path.resolve(__dirname, 'ext/config_validator.js') },
95-
{ find: /.*\/enums$/,
96-
replacement: path.resolve(__dirname, 'ext/enums.js') }
97-
]}),
98-
...esmFullBundle.plugins,
99-
visualizer(),
100-
],
101-
output: {
102-
format: 'es',
103-
file: 'dist/optimizely.browser.es.slim.js',
104-
sourcemap: true,
105-
},
50+
}
10651
}
10752

108-
const umdBundle = {
53+
const umdconfig = {
10954
plugins: [
11055
resolve({ browser: true }),
11156
commonjs({
@@ -146,7 +91,7 @@ const umdBundle = {
14691
};
14792

14893
// A separate bundle for json schema validator.
149-
const jsonSchemaBundle = {
94+
const jsonSchemaValidatorConfig = {
15095
plugins: [
15196
resolve(),
15297
commonjs(),
@@ -162,35 +107,11 @@ const jsonSchemaBundle = {
162107
}
163108
};
164109

165-
const bundles = {
166-
'cjs-node': cjsBuildFor('node'),
167-
'cjs-browser': cjsBuildFor('browser'),
168-
'cjs-react-native': cjsBuildFor('react_native'),
169-
'esm': esmBundle,
170-
'esm-full': esmFullBundle,
171-
'esm-slim': esmSlimBundle,
172-
'json-schema': jsonSchemaBundle,
173-
'umd': umdBundle,
174-
}
175-
176-
// Returns the bundle config matching the given pattern
177-
const bundlesMatching = pattern => Object.entries(bundles)
178-
.reduce((bundles, [name, config]) => {
179-
if (name.match(pattern)) bundles.push(config)
180-
return bundles
181-
}, [])
182-
183-
// Collect all --config-* options and return the matching bundle configs
184-
// Builds all bundles if no --config-* option given
185-
// --config-cjs will build all three cjs-* bundles
186-
// --config-umd will build only the umd bundle
187-
// --config-umd --config-json will build both umd and the json-schema bundles
188-
export default args => {
189-
const patterns = Object.keys(args)
190-
.filter(arg => arg.startsWith('config-'))
191-
.map(arg => arg.replace(/config-/, ''))
192-
193-
if (!patterns.length) patterns.push(/.*/)
194-
195-
return patterns.flatMap(bundlesMatching)
196-
}
110+
export default [
111+
BUILD_ALL && getCjsConfigForPlatform('node'),
112+
BUILD_ALL && getCjsConfigForPlatform('browser'),
113+
BUILD_ALL && getCjsConfigForPlatform('react_native'),
114+
BUILD_ALL && esModuleConfig,
115+
BUILD_ALL && jsonSchemaValidatorConfig,
116+
(BUILD_ALL || BUILD_UMD_BUNDLE) && umdconfig,
117+
].filter(config => config);

0 commit comments

Comments
 (0)