Skip to content

[FSSDK-10992] refactor build and export map #1007

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 1 commit into from
Feb 20, 2025
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
78 changes: 29 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,51 @@
"name": "@optimizely/optimizely-sdk",
"version": "5.3.4",
"description": "JavaScript SDK for Optimizely Feature Experimentation, Optimizely Full Stack (legacy), and Optimizely Rollouts",
"module": "dist/optimizely.browser.es.js",
"main": "dist/optimizely.node.min.js",
"browser": "dist/optimizely.browser.min.js",
"react-native": "dist/optimizely.react_native.min.js",
"typings": "dist/index.browser.d.ts",
"main": "./dist/index.node.min.js",
"browser": "./dist/index.browser.es.min.js",
"react-native": "./dist/index.react_native.min.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": {
"types": "./dist/index.node.d.ts",
"default": "./dist/optimizely.node.min.js"
"import": "./dist/index.node.es.min.mjs",
"require": "./dist/index.node.min.js"
},
"react-native": {
"types": "./dist/index.react_native.d.ts",
"default": "./dist/optimizely.react_native.min.js"
"import": "./dist/index.react_native.es.min.js",
"require": "./dist/index.react_native.min.js"
},
"browser": {
"import": "./dist/index.browser.es.min.js",
"require": "./dist/index.browser.min.js"
},
"default": {
"types": "./dist/index.browser.d.ts",
"require": "./dist/optimizely.browser.min.js",
"import": "./dist/optimizely.browser.es.js",
"default": "./dist/optimizely.browser.es.min.js"
"import": "./dist/index.node.es.min.mjs",
"require": "./dist/index.node.min.js"
}
},
"./node": {
"types": "./dist/index.node.d.ts",
"default": "./dist/optimizely.node.min.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.node.es.min.mjs",
"require": "./dist/index.node.min.js"
},
"./browser": {
"types": "./dist/index.browser.d.ts",
"require": "./dist/optimizely.browser.min.js",
"import": "./dist/optimizely.browser.es.js",
"default": "./dist/optimizely.browser.es.min.js"
"types": "./dist/index.d.ts",
"import": "./dist/index.browser.es.min.js",
"require": "./dist/index.browser.min.js"
},
"./react_native": {
"types": "./dist/index.react_native.d.ts",
"default": "./dist/optimizely.react_native.min.js"
"types": "./dist/index.d.ts",
"default": "./dist/index.react_native.min.js",
"import": "./dist/index.react_native.es.min.js",
"require": "./dist/index.react_native.min.js"
},
"./lite": {
"types": "./dist/index.lite.d.ts",
"node": "./dist/optimizely.lite.min.js",
"import": "./dist/optimizely.lite.es.js",
"default": "./dist/optimizely.lite.min.js"
},
"./dist/optimizely.lite.es": {
"types": "./dist/index.lite.d.ts",
"default": "./dist/optimizely.lite.es.js"
},
"./dist/optimizely.lite.es.js": {
"types": "./dist/index.lite.d.ts",
"default": "./dist/optimizely.lite.es.js"
},
"./dist/optimizely.lite.es.min": {
"types": "./dist/index.lite.d.ts",
"default": "./dist/optimizely.lite.es.min.js"
},
"./dist/optimizely.lite.es.min.js": {
"types": "./dist/index.lite.d.ts",
"default": "./dist/optimizely.lite.es.min.js"
},
"./dist/optimizely.lite.min": {
"types": "./dist/index.lite.d.ts",
"default": "./dist/optimizely.lite.min.js"
},
"./dist/optimizely.lite.min.js": {
"types": "./dist/index.lite.d.ts",
"default": "./dist/optimizely.lite.min.js"
"node": "./dist/index.lite.min.js",
"import": "./dist/index.lite.es.js",
"default": "./dist/index.lite.min.js"
}
},
"scripts": {
Expand All @@ -82,7 +62,7 @@
"test-umdbrowser": "npm run build-browser-umd && karma start karma.umd.conf.js --single-run",
"test-karma-local": "karma start karma.local_chrome.bs.conf.js && npm run build-browser-umd && karma start karma.local_chrome.umd.conf.js",
"prebuild": "npm run clean",
"build": "npm run genmsg && rollup -c && cp dist/index.lite.d.ts dist/optimizely.lite.es.d.ts && cp dist/index.lite.d.ts dist/optimizely.lite.es.min.d.ts && cp dist/index.lite.d.ts dist/optimizely.lite.min.d.ts",
"build": "npm run genmsg && rollup -c && cp dist/index.browser.d.ts dist/index.d.ts",
"build:win": "npm run genmsg && rollup -c && type nul > dist/optimizely.lite.es.d.ts && type nul > dist/optimizely.lite.es.min.d.ts && type nul > dist/optimizely.lite.min.d.ts",
"build-browser-umd": "rollup -c --config-umd",
"coveralls": "nyc --reporter=lcov npm test",
Expand Down
77 changes: 47 additions & 30 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,50 @@ const typescriptPluginOptions = {
}
};

const cjsBundleFor = platform => ({
plugins: [resolve(), commonjs(), typescript(typescriptPluginOptions)],
external: ['https', 'http', 'url'].concat(Object.keys({ ...dependencies, ...peerDependencies } || {})),
input: `lib/index.${platform}.ts`,
output: {
exports: 'named',
format: 'cjs',
file: `dist/optimizely.${platform}.min.js`,
plugins: [terser()],
sourcemap: true,
},
});
const cjsBundleFor = (platform, opt = {}) => {
const { minify, ext } = {
minify: true,
ext: '.js',
...opt,
};

const esmBundleFor = platform => ({
...cjsBundleFor(platform),
output: [
{
format: 'es',
file: `dist/optimizely.${platform}.es.js`,
sourcemap: true,
},
{
format: 'es',
file: `dist/optimizely.${platform}.es.min.js`,
plugins: [terser()],
const min = minify ? '.min' : '';

return {
plugins: [resolve(), commonjs(), typescript(typescriptPluginOptions)],
external: ['https', 'http', 'url'].concat(Object.keys({ ...dependencies, ...peerDependencies } || {})),
input: `lib/index.${platform}.ts`,
output: {
exports: 'named',
format: 'cjs',
file: `dist/index.${platform}${min}${ext}`,
plugins: minify ? [terser()] : undefined,
sourcemap: true,
},
],
});
}
};

const esmBundleFor = (platform, opt) => {
const { minify, ext } = {
minify: true,
ext: '.js',
...opt,
};

const min = minify ? '.min' : '';

return {
...cjsBundleFor(platform),
output: [
{
format: 'es',
file: `dist/index.${platform}.es${min}${ext}`,
plugins: minify ? [terser()] : undefined,
sourcemap: true,
},
],
}
};

const umdBundle = {
plugins: [
Expand Down Expand Up @@ -123,11 +138,13 @@ const jsonSchemaBundle = {
};

const bundles = {
'cjs-node': cjsBundleFor('node'),
'cjs-browser': cjsBundleFor('browser'),
'cjs-react-native': cjsBundleFor('react_native'),
'cjs-node-min': cjsBundleFor('node'),
'cjs-browser-min': cjsBundleFor('browser'),
'cjs-react-native-min': cjsBundleFor('react_native'),
'cjs-lite': cjsBundleFor('lite'),
esm: esmBundleFor('browser'),
'esm-browser-min': esmBundleFor('browser'),
'esm-node-min': esmBundleFor('node', { ext: '.mjs' }),
'esm-react-native-min': esmBundleFor('react_native'),
'esm-lite': esmBundleFor('lite'),
'json-schema': jsonSchemaBundle,
umd: umdBundle,
Expand Down
Loading