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

Add Conditional Exports in Popper v2 #1526

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions .config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@ import flowEntry from 'rollup-plugin-flow-entry';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
import pkg from '../package.json';

const getFileName = (input) => input.split('/')[1].split('.')[0];
const getFileName = (input) => input.split('/').reverse()[0].split('.')[0];

const inputs = ['src/popper.js', 'src/popper-lite.js', 'src/popper-base.js', 'src/enums.js'];
const bundles = [
{ inputs, format: 'umd', dir: 'dist', minify: true, flow: true },
{ inputs, format: 'umd', dir: 'dist' },
{ inputs, format: 'cjs', dir: 'dist', flow: true },
{ inputs: ['dist/esm/index.js'], format: 'esm', dir: 'dist', minify: true },
{ inputs: ['lib/index.js'], format: 'esm', dir: 'dist', development: true },
];

const configs = bundles
.map(({ inputs, dir, format, minify, flow }) =>
.map(({ inputs, dir, format, minify, flow, development }) =>
inputs.map((input) => ({
input,
plugins: [
format === 'umd' &&
replace({
__DEV__: minify ? 'false' : 'true',
}),
format === 'esm' && development &&
replace({
'process.env.NODE_ENV': '"development"',
}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I didn't want to alter anything about the existing build, __DEV__ will still be replaced by babel-plugin-dev-expression. Then I replace the process.env.NODE_ENV reference after that.

babel({ babelHelpers: 'bundled' }),
// The two minifiers together seem to procude a smaller bundle 🤷‍♂️
minify && compiler(),
Expand All @@ -35,12 +41,12 @@ const configs = bundles
bundleSize(),
visualizer({
sourcemap: true,
filename: `stats/${getFileName(input)}${minify ? '-min' : ''}.html`,
filename: `stats/${getFileName(input)}${development ? '-development' : ''}${minify ? '-min' : ''}.html`,
}),
].filter(Boolean),
output: {
name: 'Popper',
file: `${dir}/${format}/${getFileName(input)}${
file: `${dir}/${format}/${getFileName(input)}${development ? '.development' : ''}${
minify ? '.min' : ''
}.js`,
format,
Expand Down
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
"main": "dist/cjs/popper.js",
"main:umd": "dist/umd/popper.js",
"module": "lib/index.js",
"exports": {
".": {
"import": {
"development": "./dist/esm/index.development.js",
"production": "./dist/esm/index.min.js",
"default": "./lib/index.js"
},
"require": "./dist/cjs/popper.js"
},
"./package.json": "./package.json"
},
"unpkg": "dist/umd/popper.min.js",
"author": "Federico Zivolo <federico.zivolo@gmail.com>",
"license": "MIT",
Expand Down