Skip to content

Commit

Permalink
expose es6 and commonjs modules, address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsnyder committed Nov 13, 2020
1 parent 6cc1416 commit 9b459e2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 63 deletions.
4 changes: 2 additions & 2 deletions coverageignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ module.exports = [
"**/.*",
"**/constants/**",
"**/index.js",
"src/baseCode.js",
"src/standAlone.js"
"baseCode.js",
"standalone.js"
];
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
"name": "@adobe/alloy",
"version": "2.3.0",
"description": "Adobe Experience Platform Web SDK",
"module": "dist/index.js",
"main": "dist/main.js",
"module": "dist/module.js",
"files": [
"dist/index.js"
"dist/main.js",
"dist/module.js"
],
"scripts": {
"install": "cd sandbox && npm install",
Expand Down
98 changes: 67 additions & 31 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,53 @@ const minify = process.env.MINIFY;
const destDirectory = destDirectoryByBuildTarget[buildTarget];

const minifiedExtension = minify ? ".min" : "";
const baseCodeTerser = terser({
mangle: true,
compress: {
unused: false

const BASE_CODE = "baseCode";
const STANDALONE = "standalone";
const MODULE = "module";
const MAIN = "main";
const buildPlugins = version => {
const plugins = [
resolve({
preferBuiltins: false,
// Support the browser field in dependencies' package.json.
// Useful for the uuid package.
mainFields: ["module", "main", "browser"]
}),
commonjs()
];
if (version !== MODULE) {
plugins.push(babel());
}
});

const plugins = [
resolve({
preferBuiltins: false,
// Support the browser field in dependencies' package.json.
// Useful for the uuid package.
mainFields: ["module", "main", "browser"]
}),
commonjs(),
babel()
];

if (buildTarget !== buildTargets.DEV) {
plugins.push(
license({
banner: {
content: {
file: path.join(__dirname, "LICENSE_BANNER")
if (minify && version === BASE_CODE) {
plugins.push(
terser({
mangle: true,
compress: {
unused: false
}
}
})
);
}
})
);
}
if (minify && version === STANDALONE) {
plugins.push(terser());
}

if (buildTarget !== buildTargets.DEV && version !== BASE_CODE) {
plugins.push(
license({
banner: {
content: {
file: path.join(__dirname, "LICENSE_BANNER")
}
}
})
);
}

return plugins;
};

const config = [];

Expand All @@ -73,12 +91,12 @@ if (buildTarget === buildTargets.PROD) {
format: "iife"
}
],
plugins: minify ? [...plugins, baseCodeTerser] : plugins
plugins: buildPlugins(BASE_CODE)
});
}

config.push({
input: "src/standAlone.js",
input: "src/standalone.js",
output: [
{
file: `${destDirectory}alloy${minifiedExtension}.js`,
Expand All @@ -90,15 +108,33 @@ config.push({
"}\n"
}
],
plugins: minify ? [...plugins, terser()] : plugins
plugins: buildPlugins(STANDALONE)
});

if (buildTarget === buildTargets.PROD && !minify) {
config.push({
input: "src/index.js",
output: [
{
file: `${destDirectory}index.js`,
file: `${destDirectory}main.js`,
format: "cjs"
}
],
// The @adobe/reactor-* dependencies are specified as peerDependencies so no need to include them in the
// module build. The Launch extension does not need them included.
external(name) {
return /^@adobe\/reactor-/.test(name);
},
plugins: buildPlugins(MAIN)
});
}

if (buildTarget === buildTargets.PROD && !minify) {
config.push({
input: "src/index.js",
output: [
{
file: `${destDirectory}module.js`,
format: "es"
}
],
Expand All @@ -107,7 +143,7 @@ if (buildTarget === buildTargets.PROD && !minify) {
external(name) {
return /^@adobe\/reactor-/.test(name);
},
plugins
plugins: buildPlugins(MODULE)
});
}

Expand Down
14 changes: 0 additions & 14 deletions test/unit/specs/baseCode.spec.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/unit/specs/standalone.spec.js

This file was deleted.

0 comments on commit 9b459e2

Please sign in to comment.