Skip to content
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

refactor(build): rollup configuration files #604

Merged
merged 10 commits into from
Aug 10, 2022
4 changes: 2 additions & 2 deletions buildspec.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ phases:
nodejs: 12
build:
commands:
- npm install --unsafe-perm
- npm ci
- npm run test
- npm run buildProdBrowser
- node -r esm integrationBuildScript.js
- npm run buildAllIntegrations
- sed -i -e 's|{{RS_BUGSNAG_API_KEY}}|'$RS_BUGSNAG_API_KEY'|' dist/rudder-analytics.min.js
- aws s3 cp dist/rudder-analytics.min.js s3://$S3_BUCKET_NAME/v1.1/rudder-analytics.min.js --cache-control max-age=3600 --acl public-read
- aws s3 cp dist/rudder-analytics.min.js.map s3://$S3_BUCKET_NAME/v1.1/rudder-analytics.min.js.map --cache-control max-age=3600 --acl public-read
Expand Down
22 changes: 8 additions & 14 deletions buildspec.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@ phases:
nodejs: 12
build:
commands:
- npm install --unsafe-perm
- npm ci
- npm run test
- npm run buildProdBrowser
- node -r esm integrationBuildScript.js
- sed -i -e 's|rudder-analytics.min.js.map|rudder-analytics-staging.min.js.map|' -e 's|{{RS_BUGSNAG_API_KEY}}|'$RS_BUGSNAG_API_KEY'|' dist/rudder-analytics.min.js
- aws s3 cp dist/rudder-analytics.min.js s3://$S3_BUCKET_NAME/v1.1/rudder-analytics-staging.min.js --cache-control max-age=3600 --acl public-read
- aws s3 cp dist/rudder-analytics.min.js.map s3://$S3_BUCKET_NAME/v1.1/rudder-analytics-staging.min.js.map --cache-control max-age=3600 --acl public-read
- mkdir dist/temp
- cp dist/integrations/* dist/temp
- for file in dist/temp/*.min.js ; do old_name=$(basename "$file"); old_name=$(echo $old_name.map); new_name=$(echo $old_name | awk '{split($0, tmp, "."); print sprintf("%s-staging.%s.%s.%s", tmp[1], tmp[2], tmp[3], tmp[4])}'); sed -i 's|'$old_name'|'$new_name'|' $file; done
- for file in dist/temp/*.min.js ; do old_name=$(basename "$file"); new_name=$(echo $old_name | awk '{split($0, tmp, "."); print sprintf("%s-staging.%s.%s", tmp[1], tmp[2], tmp[3])}'); mv "dist/temp/$old_name" "dist/temp/$new_name"; done
- for file in dist/temp/*.min.js.map ; do old_name=$(basename "$file"); new_name=$(echo $old_name | awk '{split($0, tmp, "."); print sprintf("%s-staging.%s.%s.%s", tmp[1], tmp[2], tmp[3], tmp[4])}'); mv "dist/temp/$old_name" "dist/temp/$new_name"; done
- aws s3 cp dist/temp/ s3://$S3_BUCKET_NAME/v1.1/js-integrations/ --recursive --cache-control max-age=3600 --acl public-read
- rm -rf dist/temp
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/v1.1/rudder-analytics-staging.min.js" "/v1.1/rudder-analytics-staging.min.js.map" "/v1.1/js-integrations"
- npm run buildProdBrowser --staging=true
- npm run buildAllIntegrations --staging=true
- sed -i -e 's|{{RS_BUGSNAG_API_KEY}}|'$RS_BUGSNAG_API_KEY'|' dist/rudder-analytics-staging.min.js
- aws s3 cp dist/rudder-analytics-staging.min.js s3://$S3_BUCKET_NAME/v1.1/rudder-analytics-staging.min.js --cache-control max-age=3600 --acl public-read
- aws s3 cp dist/rudder-analytics-staging.min.js.map s3://$S3_BUCKET_NAME/v1.1/rudder-analytics-staging.min.js.map --cache-control max-age=3600 --acl public-read
- aws s3 cp dist/integrations/ s3://$S3_BUCKET_NAME/v1.1/js-integrations/ --recursive --cache-control max-age=3600 --acl public-read
- aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_DISTRIBUTION_ID --paths "/v1.1/rudder-analytics-staging.min.js" "/v1.1/rudder-analytics-staging.min.js.map" "/v1.1/js-integrations*"
artifacts:
files:
- '**/*'
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "npm run buildProdBrowser && sed 's/var rudderanalytics/rudderanalytics/g' dist/rudder-analytics.min.js > __tests__/prodsdk.js && jest --coverage --verbose",
"buildDevBrowser": "NODE_ENV=false uglify=false rollup -c",
"buildProdBrowser": "NODE_ENV=false PROD_DEBUG=true ENV=prod uglify=true rollup -c",
"buildProdBrowser": "NODE_ENV=false PROD_DEBUG=true STAGING=$npm_config_staging ENV=prod uglify=true rollup -c",
"buildProdBrowserDebug": "NODE_ENV=false ENV=prod PROD_DEBUG_INLINE=true uglify=true rollup -c",
"buildProdBrowserGzip": "NODE_ENV=false ENV=prod ENC=gzip uglify=true rollup -c",
"buildProdBrowserBrotli": "NODE_ENV=false ENV=prod ENC=br uglify=true rollup -c",
Expand All @@ -20,14 +20,14 @@
"buildDevIntegrationCLI": "PROD_DEBUG=true NODE_ENV=false uglify=false INTG_NAME=$npm_config_intg rollup --config rollup.intgConfig.js",
"buildProdIntegration": "PROD_DEBUG=true NODE_ENV=false ENV=prod uglify=true INTG_NAME=AdobeAnalytics rollup --config rollup.intgConfig.js",
"buildProdIntegrationCLI": "PROD_DEBUG=true NODE_ENV=false ENV=prod uglify=true INTG_NAME=$npm_config_intg rollup --config rollup.intgConfig.js",
"buildAllIntegrations": "BUNDLE_SIZE_VISUALIZER=false node -r esm integrationBuildScript.js",
"buildAllIntegrations": "BUNDLE_SIZE_VISUALIZER=false STAGING=$npm_config_staging node -r esm integrationBuildScript.js",
"bundle-size-visual-integration": "ENV=prod PROD_DEBUG=true uglify=true visualizer=true INTG_NAME=AdobeAnalytics rollup --config rollup.intgConfig.js",
"bundle-size-visual-integration-cli": "ENV=prod PROD_DEBUG=true uglify=true visualizer=true INTG_NAME=$npm_config_intg rollup --config rollup.intgConfig.js",
"format": "prettier --write '**/*.js'",
"lint": "eslint . --fix",
"lint:check": "eslint . || exit 1",
"prepare": "husky install",
"clean": "rm -rf dist/integrations && rm -f dist/*.js*"
"clean": "find dist -type f -name '*.js' -delete && find dist -type f -name '*.js.map' -delete && rm -rf dist/integrations"
},
"author": "",
"license": "ISC",
Expand Down
177 changes: 12 additions & 165 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,171 +1,18 @@
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import { terser } from "rollup-plugin-terser";
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
import json from "@rollup/plugin-json";
import gzipPlugin from "rollup-plugin-gzip";
import brotli from "rollup-plugin-brotli";
import visualizer from "rollup-plugin-visualizer";
import filesize from "rollup-plugin-filesize";
import * as webPackage from "./package.json";
// eslint-disable-next-line import/no-relative-packages
import * as npmPackage from "./dist/rudder-sdk-js/package.json";
import { getOutputConfiguration, getOutputFilePath, getDefaultConfig } from './rollupUtils';

let distFileName = "";
let { version } = webPackage;
let moduleType = "cdn";
switch (process.env.ENV) {
case "prod":
switch (process.env.ENC) {
case "gzip":
if (process.env.PROD_DEBUG_INLINE === "true") {
distFileName = "dist/rudder-analytics-map.min.gzip.js";
} else {
distFileName = "dist/rudder-analytics.min.gzip.js";
}
break;
case "br":
if (process.env.PROD_DEBUG_INLINE === "true") {
distFileName = "dist/rudder-analytics-map.min.br.js";
} else {
distFileName = "dist/rudder-analytics.min.br.js";
}
break;
default:
if (process.env.PROD_DEBUG_INLINE === "true") {
distFileName = "dist/rudder-analytics-map.min.js";
} else {
distFileName = "dist/rudder-analytics.min.js";
}
break;
}
break;
default:
distFileName = "dist/rudder-analytics.js";
break;
}
const outDir = 'dist';
const distName = 'rudder-analytics';

const outputFiles = [];
if (process.env.NPM === "true") {
outputFiles.push({
file: "dist/rudder-sdk-js/index.js",
format: "umd",
name: "rudderanalytics",
});
version = npmPackage.version;
moduleType = "npm";
} else {
outputFiles.push({
file: distFileName,
format: "iife",
name: "rudderanalytics",
sourcemap:
process.env.PROD_DEBUG_INLINE === "true"
? "inline"
: !!process.env.PROD_DEBUG,
});
}
const outFilePath = getOutputFilePath(outDir, distName);

const outputFiles = getOutputConfiguration(
`${outDir}/rudder-sdk-js`,
'rudderanalytics',
outFilePath,
);

export default {
input: "analytics.js",
external: [],
...getDefaultConfig(distName),
input: 'analytics.js',
output: outputFiles,
plugins: [
replace({
preventAssignment: true,
"process.browser": process.env.NODE_ENV !== "true",
"process.prod": process.env.ENV === "prod",
"process.package_version": version,
"process.module_type": moduleType,
}),
resolve({
jsnext: true,
browser: true,
preferBuiltins: false,
}),

commonjs({
include: "node_modules/**",
/* namedExports: {
// left-hand side can be an absolute path, a path
// relative to the current directory, or the name
// of a module in node_modules
Xmlhttprequest: ["Xmlhttprequest"]
} */
}),

json(),
globals(),
builtins(),

babel({
inputSourceMap: true,
babelHelpers: "bundled",
exclude: ["node_modules/@babel/**", "node_modules/core-js/**"],
presets: [
[
"@babel/env",
{
corejs: "3.6",
useBuiltIns: "entry",
targets: {
edge: "15",
firefox: "40",
ie: "10",
chrome: "37",
safari: "7",
opera: "23",
},
},
],
],
plugins: [
[
"@babel/plugin-proposal-class-properties",
{
loose: true,
},
],
[
"@babel/plugin-proposal-private-property-in-object",
{
loose: true,
},
],
[
"@babel/plugin-proposal-private-methods",
{
loose: true,
},
],
["@babel/plugin-transform-arrow-functions"],
["@babel/plugin-transform-object-assign"],
],
}),
process.env.uglify === "true" && terser({
// remove all comments
format: {
comments: false,
},
}),
process.env.ENC === "gzip" && gzipPlugin(),
process.env.ENC === "br" && brotli(),
process.env.visualizer === "true" &&
process.env.uglify === "true" &&
visualizer({
filename: "./stats/rudder-analytics.html",
title: "Rollup Visualizer - rudder-analytics",
sourcemap: true,
open: true,
gzipSize: true,
brotliSize: true,
}),
filesize({
showBeforeSizes: "build",
showBrotliSize: true,
}),
],
};
Loading