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

Allows the Cedar library to be tree shaken in consuming applications #131

Merged
merged 7 commits into from
May 3, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6,784 changes: 3,890 additions & 2,894 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rei/cedar",
"version": "13.3.2",
"version": "13.4.0",
"description": "REI Cedar Component Library",
"homepage": "https://rei.github.io/rei-cedar/",
"license": "MIT",
Expand All @@ -13,10 +13,10 @@
},
"author": "REI Software Engineering",
"main": "./dist/cedar.umd.js",
"module": "./dist/cedar.mjs",
"module": "./dist/src/lib.mjs",
"exports": {
".": {
"import": "./dist/cedar.mjs",
"import": "./dist/src/lib.mjs",
"require": "./dist/cedar.umd.js"
},
"./dist/": "./dist/"
Expand Down Expand Up @@ -118,15 +118,11 @@
}
},
"dependencies": {
"core-js": "^3.22.7",
"lodash-es": "^4.17.21",
"tabbable": "^4.0.0",
"vue": "^3.2.23"
"tabbable": "^4.0.0"
},
"peerDependencies": {
"core-js": "^3.22.7",
"lodash-es": "^4.17.21",
"tabbable": "^4.0.0",
"vue": "^3.2.23"
}
}
9 changes: 7 additions & 2 deletions rollupOptions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import { babel } from '@rollup/plugin-babel';
import browserTargets from './browserTargets.mjs';

export default {
external: ['vue', 'core-js', 'lodash-es', 'tabbable'], // Externalize peerDependencies
// external: ['vue', 'core-js', 'lodash-es', 'tabbable'], // Externalize peerDependencies
external: (id) => ['vue', 'core-js', 'lodash-es', 'tabbable'].some(
(dep) => dep === id || id.startsWith(`${dep}/`),
),
output: {
globals: {
vue: 'Vue',
},
preserveModules: true,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The magic

},
plugins: [
babel({
Expand All @@ -21,7 +25,8 @@ export default {
{
modules: false, // don't convert ESM modules, as that breaks tree shaking
targets: browserTargets, // polyfill based on supported browsers
corejs: { // use corejs@3 for polyfills
corejs: {
// use corejs@3 for polyfills
version: '3.26', // see https://github.com/zloirock/core-js#babelpreset-env
},
useBuiltIns: 'usage', // polyfill based on usage in source code.
Expand Down
2 changes: 1 addition & 1 deletion src/components/accordion/CdrAccordionGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
defineComponent, useCssModule, computed, ref, reactive, onMounted, provide,
} from 'vue';
import debounce from 'lodash-es/debounce';
import { debounce } from 'lodash-es';
Copy link
Collaborator Author

@HeavyMedl HeavyMedl Apr 27, 2023

Choose a reason for hiding this comment

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

We need to destructure the named exports from the lodash-es module, which points to the module entry defined in lodash-es/package.json. Otherwise, in the context of testing in consuming applications, Vitest whines about not being able to import lodash-es/debounce without a .js extension.

import propValidator from '../../utils/propValidator';
import getCurrentBreakpoint from '../../mixins/breakpoints';

Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/CdrModal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import debounce from 'lodash-es/debounce';
import { debounce } from 'lodash-es';
import tabbable from 'tabbable';
import {
useCssModule, computed, ref, watch, onMounted, nextTick, onUnmounted, defineComponent,
Expand Down
2 changes: 1 addition & 1 deletion src/components/popup/CdrPopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
defineComponent, useCssModule, computed, ref, watch, nextTick, onMounted, onUnmounted,
} from 'vue';
import debounce from 'lodash-es/debounce';
import { debounce } from 'lodash-es';
import propValidator from '../../utils/propValidator';
import calculatePlacement from './calculatePlacement';
import mapClasses from '../../utils/mapClasses';
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/CdrTabPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
computed, defineComponent, inject, useCssModule, watch,
} from 'vue';
import kebabCase from 'lodash-es/kebabCase';
import { kebabCase } from 'lodash-es';

export default defineComponent({
name: 'CdrTabPanel',
Expand Down
2 changes: 1 addition & 1 deletion src/components/tabs/CdrTabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
defineComponent, ref, provide, onMounted, nextTick, computed, useCssModule,
} from 'vue';
import debounce from 'lodash-es/debounce';
import { debounce } from 'lodash-es';
import {
CdrColorBackgroundPrimary, CdrSpaceOneX, CdrSpaceHalfX,
} from '@rei/cdr-tokens/dist/js/cdr-tokens.mjs';
Expand Down
2 changes: 1 addition & 1 deletion src/dev/SinkWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<script>

import { CdrRadio } from 'srcdir/lib';
import upperFirst from 'lodash-es/upperFirst';
import { upperFirst } from 'lodash-es';

export default {
name: 'SinkWrapper',
Expand Down
4 changes: 3 additions & 1 deletion vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { fileURLToPath, URL } from 'url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
// import path from 'path';
import options from './rollupOptions.mjs';

const version = process.env.npm_package_version;
Expand All @@ -12,7 +13,8 @@ export default defineConfig({
build: {
lib: {
entry: './src/lib.js',
name: 'cedar',
formats: ['es'],
fileName: '[name]',
},
rollupOptions: options,
},
Expand Down