File tree Expand file tree Collapse file tree 6 files changed +149
-188
lines changed
Expand file tree Collapse file tree 6 files changed +149
-188
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @quickpickle/playwright " : patch
3+ " quickpickle " : patch
4+ ---
5+
6+ Fix and optimize lodash imports for CommonJS
Original file line number Diff line number Diff line change 3535 " dist"
3636 ],
3737 "scripts" : {
38- "build" : " rollup -c" ,
38+ "build" : " rollup -c && FORMAT=cjs rollup -c " ,
3939 "type-check" : " tsc --noEmit" ,
4040 "test:watch" : " vitest" ,
4141 "test" : " vitest --run"
4646 "@cucumber/gherkin" : " ^29.0.0" ,
4747 "@cucumber/messages" : " ^22.0.0" ,
4848 "@cucumber/tag-expressions" : " ^6.1.1" ,
49+ "lodash" : " ^4.17.21" ,
4950 "lodash-es" : " ^4.17.21"
5051 },
5152 "devDependencies" : {
53+ "@optimize-lodash/esbuild-plugin" : " ^3.0.0" ,
54+ "@optimize-lodash/rollup-plugin" : " ^5.0.0" ,
5255 "@rollup/plugin-replace" : " ^6.0.1" ,
5356 "@rollup/plugin-terser" : " ^0.4.4" ,
5457 "@rollup/plugin-typescript" : " ^12.1.1" ,
5760 "@types/node" : " ^18.19.66" ,
5861 "@vitest/browser" : " ^2.1.6" ,
5962 "playwright" : " ^1.49.0" ,
60- "rollup" : " ^3.29.5 " ,
63+ "rollup" : " ^4.27.4 " ,
6164 "typescript" : " ^5.7.2" ,
6265 "vite" : " ^6.0.7" ,
6366 "vitest" : " ^2.1.6"
Original file line number Diff line number Diff line change 11import typescript from '@rollup/plugin-typescript' ;
22import replace from '@rollup/plugin-replace' ;
3+ import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin'
4+
5+ let cjs = process . env . FORMAT === 'cjs' ? 'cjs' : '' ;
36
47export default {
58 input : 'src/index.ts' ,
69 output : [
710 {
8- file : 'dist/index.cjs' ,
9- format : 'cjs' ,
10- sourcemap : true ,
11- exports : 'named' ,
12- } ,
13- {
14- file : 'dist/index.esm.js' ,
15- format : 'esm' ,
11+ file : `dist/index.${ cjs || 'esm.js' } ` ,
12+ format : cjs || 'esm' ,
1613 sourcemap : true ,
1714 exports : 'named' ,
1815 } ,
@@ -23,8 +20,12 @@ export default {
2320 values : {
2421 'import.meta?.env?.MODE' : JSON . stringify ( 'production' ) ,
2522 'process?.env?.NODE_ENV' : JSON . stringify ( 'production' ) ,
23+ 'lodash-es' : cjs ? 'lodash' : 'lodash-es' ,
2624 }
2725 } ) ,
26+ optimizeLodashImports ( {
27+ appendDotJs : false ,
28+ } ) ,
2829 typescript ( {
2930 tsconfig : './tsconfig.json' ,
3031 declaration : true ,
@@ -37,5 +38,6 @@ export default {
3738 '@cucumber/messages' ,
3839 '@cucumber/tag-expressions' ,
3940 'lodash-es' ,
41+ 'lodash' ,
4042 ]
4143} ;
Original file line number Diff line number Diff line change 5959 " dist"
6060 ],
6161 "scripts" : {
62- "build" : " rollup -c" ,
62+ "build" : " rollup -c && FORMAT=cjs rollup -c " ,
6363 "playwright-install-ci" : " playwright install-deps && playwright install chromium" ,
6464 "type-check" : " tsc --noEmit" ,
6565 "test:watch" : " vitest" ,
6868 "author" : " David Hunt" ,
6969 "dependencies" : {
7070 "@playwright/test" : " ^1.49.0" ,
71+ "lodash" : " ^4.17.21" ,
7172 "lodash-es" : " ^4.17.21" ,
7273 "pixelmatch" : " ^6.0.0" ,
7374 "playwright" : " ^1.49.0" ,
7677 "vite" : " ^5.4.11"
7778 },
7879 "devDependencies" : {
80+ "@optimize-lodash/rollup-plugin" : " ^5.0.0" ,
7981 "@rollup/plugin-replace" : " ^6.0.1" ,
8082 "@rollup/plugin-typescript" : " ^12.1.1" ,
8183 "@types/jest-image-snapshot" : " ^6.4.0" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,9 @@ import typescript from '@rollup/plugin-typescript';
22import replace from '@rollup/plugin-replace' ;
33import glob from 'fast-glob' ;
44import path from 'node:path' ;
5+ import { optimizeLodashImports } from '@optimize-lodash/rollup-plugin'
6+
7+ let cjs = process . env . FORMAT === 'cjs' ? 'cjs' : '' ;
58
69const input = Object . fromEntries (
710 glob . sync ( 'src/**/*.ts' ) . map ( file => [
@@ -16,27 +19,24 @@ export default {
1619 output : [
1720 {
1821 dir : 'dist' ,
19- format : ' cjs',
22+ format : cjs || 'esm ',
2023 sourcemap : true ,
2124 exports : 'named' ,
22- entryFileNames : ' [name].cjs'
25+ entryFileNames : ` [name].${ cjs || 'mjs' } `
2326 } ,
24- {
25- dir : 'dist' ,
26- format : 'esm' ,
27- sourcemap : true ,
28- exports : 'named' ,
29- entryFileNames : '[name].mjs'
30- }
3127 ] ,
3228 plugins : [
3329 replace ( {
3430 preventAssignment : true ,
3531 values : {
3632 'import.meta?.env?.MODE' : JSON . stringify ( 'production' ) ,
3733 'process?.env?.NODE_ENV' : JSON . stringify ( 'production' ) ,
34+ 'lodash-es' : cjs ? 'lodash' : 'lodash-es' ,
3835 }
3936 } ) ,
37+ optimizeLodashImports ( {
38+ appendDotJs : false ,
39+ } ) ,
4040 typescript ( {
4141 tsconfig : './tsconfig.json' ,
4242 declaration : true ,
@@ -51,6 +51,7 @@ export default {
5151 'node:url' ,
5252 'node:fs' ,
5353 'lodash-es' ,
54+ 'lodash' ,
5455 'pngjs' ,
5556 'pixelmatch' ,
5657 ]
You can’t perform that action at this time.
0 commit comments