Skip to content

Commit

Permalink
Add unpkg key to package.json
Browse files Browse the repository at this point in the history
This provides a completely bundled distribution, ready importing from CDNs like unpkg.com for use in sandboxes like Codepen.  It allows this code to work:

```typescript
import { create as createJSS } from 'https://unpkg.com/jss';
```

The PR is a work-in-progress, but I'd rather start a conversation with an example than with prose.  As it is, I can't get `sizeSnapshot` to work with the bundled version.

I also wonder how best to handle plugins/presets.  The easiest options would be to add `unpkg` entry points to each `package`, and force authors to use multiple imports:

```typescript
import { create as createJSS } from 'https://unpkg.com/jss';
import createDefaultJSSPreset from 'https://unpkg.com/jss-preset-default';
```

I wonder what the best way to produce a batteries-included bundle is.  Perhaps there should be another bundle `jss-all` that exports all the other packages.  Then usage would be:

```typescript
import * as jssAll from 'https://unpkg.com/jss-all';

const jss = jssAll.create(jssAll.preset());
```
  • Loading branch information
appsforartists committed Dec 13, 2018
1 parent bec70a0 commit 28bb032
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/jss-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"homepage": "https://cssinjs.org/jss-preset-default",
"main": "dist/jss-preset-default.cjs.js",
"module": "dist/jss-preset-default.esm.js",
"unpkg": "dist/jss-preset-default.bundle.js",
"typings": "./src/index.d.ts",
"author": {
"name": "Oleg Slobodskoi",
Expand Down
1 change: 1 addition & 0 deletions packages/jss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"homepage": "https://cssinjs.org/",
"main": "dist/jss.cjs.js",
"module": "dist/jss.esm.js",
"unpkg": "dist/jss.bundle.js",
"typings": "./src/index.d.ts",
"author": {
"name": "Oleg Slobodskoi",
Expand Down
17 changes: 17 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,22 @@ export default [
replace({'process.env.VERSION': JSON.stringify(pkg.version)}),
sizeSnapshot(snapshotOptions)
]
},

{
input,
output: {file: pkg.unpkg, format: 'esm'},
plugins: [
nodeResolve(),
babel(getBabelOptions({useESModules: true})),
commonjs(commonjsOptions),
nodeGlobals({process: false}),
replace({
'process.env.VERSION': JSON.stringify(pkg.version)
})
// sizeSnapshot barfs with
// [!] (size-snapshot plugin) Error: Error transforming bundle with 'size-snapshot' plugin: ModuleNotFoundError: Module not found: Error: Can't resolve 'jss/node_modules/rollup-plugin-size-snapshot/node_modules/webpack/buildin/harmony-module.js' in '/'
// sizeSnapshot(snapshotOptions),
]
}
]

0 comments on commit 28bb032

Please sign in to comment.