Skip to content

Commit

Permalink
feat: introduce pure bundle (JS and CSS separated) (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: Haibo <[email protected]>
  • Loading branch information
francoischalifour and Nomango authored Nov 16, 2023
1 parent efa7430 commit 0a05b46
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ Assuming you add the `data-zoomable` attribute to your images:
mediumZoom('[data-zoomable]')
```

> [!TIP]
> If you want to control when to inject the Medium Zoom CSS styles, you can use the pure JavaScript bundle:
>
> ```js
> import mediumZoom from 'medium-zoom/dist/pure'
> import 'medium-zoom/dist/style.css'
> ```
## API
```ts
Expand Down
12 changes: 12 additions & 0 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{
"files": [
{
"path": "dist/style.css",
"maxSize": "250 B"
},
{
"path": "dist/medium-zoom.esm.js",
"maxSize": "5 kB"
},
{
"path": "dist/medium-zoom.min.js",
"maxSize": "3.25 kB"
},
{
"path": "dist/pure/index.js",
"maxSize": "4.75 kB"
},
{
"path": "dist/pure/medium-zoom.min.umd.js",
"maxSize": "2.75 kB"
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dev": "rollup --config --watch",
"prebuild": "yarn run clean",
"build": "rollup --config",
"postbuild": "cp ./src/medium-zoom.d.ts ./dist",
"postbuild": "cp ./src/medium-zoom.d.ts ./dist && cp ./src/medium-zoom.d.ts ./dist/pure/index.d.ts",
"prepublishOnly": "npm run build",
"lint": "eslint .",
"format": "prettier --write *.{js,json,css,md} && yarn run lint --fix",
Expand Down
64 changes: 52 additions & 12 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const sharedPlugins = [
showGzippedSize: true,
}),
]
const prettifyPlugin = uglify({
compress: false,
mangle: false,
output: {
beautify: true,
indent_level: 2,
preamble: banner,
},
})

export default [
{
Expand All @@ -45,18 +54,7 @@ export default [
file: pkg.main.replace('.min', ''),
format: 'umd',
},
plugins: [
...sharedPlugins,
uglify({
compress: false,
mangle: false,
output: {
beautify: true,
indent_level: 2,
preamble: banner,
},
}),
],
plugins: [...sharedPlugins, prettifyPlugin],
},
{
input: 'src/index.js',
Expand All @@ -67,4 +65,46 @@ export default [
},
plugins: [...sharedPlugins, terser(), license({ banner })],
},
// pure
{
input: 'src/medium-zoom.js',
output: {
file: 'dist/pure/index.js',
format: 'es',
},
plugins: [...sharedPlugins, license({ banner })],
},
{
input: 'src/medium-zoom.js',
output: {
name: 'mediumZoom',
file: 'dist/pure/medium-zoom.umd.js',
format: 'umd',
},
plugins: [...sharedPlugins, prettifyPlugin],
},
{
input: 'src/medium-zoom.js',
output: {
name: 'mediumZoom',
file: 'dist/pure/medium-zoom.min.umd.js',
format: 'umd',
},
plugins: [...sharedPlugins, terser(), license({ banner })],
},
// style
{
input: 'src/medium-zoom.css',
output: {
file: 'dist/style.css',
format: 'es',
},
plugins: [
postcss({
extract: true,
minimize: true,
}),
license({ banner }),
],
},
]

0 comments on commit 0a05b46

Please sign in to comment.