Skip to content

Commit

Permalink
Merge pull request #248 from thysultan/fix/nodes-with-partial-esm-sup…
Browse files Browse the repository at this point in the history
…port

Create commonjs package scope for the package.json#main file
  • Loading branch information
thysultan authored Dec 2, 2020
2 parents 99afc80 + 9af06e2 commit e329ed5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"bugs": "https://github.com/thysultan/stylis.js/issues",
"sideEffects": false,
"type": "module",
"main": "dist/stylis.js",
"main": "dist/umd/stylis.js",
"module": "dist/stylis.mjs",
"react-native": "./index.js",
"exports": {
"import": "./index.js",
"require": "./dist/stylis.cjs"
"require": "./dist/umd/stylis.js"
},
"files": [
"index.js",
Expand Down
19 changes: 11 additions & 8 deletions script/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import {join} from 'path'
import {terser} from 'rollup-plugin-terser'
import size from 'rollup-plugin-size'

const emitPackageScopeFile = (type) => {
return {
name: 'emit-package-scope-file',
generateBundle() {
this.emitFile({ type: 'asset', fileName: 'package.json', source: `{ "type": "${type}" }\n` });
}
};
}

const options = {mangle: true, compress: false, toplevel: true}
const defaults = {
onwarn(warning, warn) {
Expand All @@ -21,14 +30,8 @@ export default ({configSrc = './', configInput = join(configSrc, 'index.js')}) =
{
...defaults,
input: configInput,
output: [{file: join(configSrc, 'dist', 'stylis.js'), format: 'umd', name: 'stylis', freeze: false, sourcemap: true}],
plugins: [terser(options), size()]
},
{
...defaults,
input: configInput,
output: [{file: join(configSrc, 'dist', 'stylis.cjs'), format: 'umd', name: 'stylis', freeze: false, sourcemap: true}],
plugins: [terser(options), size()]
output: [{file: join(configSrc, 'dist', 'umd', 'stylis.js'), format: 'umd', name: 'stylis', freeze: false, sourcemap: true}],
plugins: [emitPackageScopeFile('commonjs'), terser(options), size()]
},
{
...defaults,
Expand Down

0 comments on commit e329ed5

Please sign in to comment.