-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build: use mql as fetcher * refactor: access methods directly * build: tiny badge * fix: dependency in the right place * build: tweaks * build: remove size-limit * fix: vanilla bundle * fix: revert modulesOnly * build: mql as global dependency * build: add minify version * build: tweaks
- Loading branch information
Showing
8 changed files
with
153 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,80 @@ | ||
import nodeResolve from 'rollup-plugin-node-resolve' | ||
import visualizer from 'rollup-plugin-visualizer' | ||
import { terser } from 'rollup-plugin-terser' | ||
import filesize from 'rollup-plugin-filesize' | ||
import { terser } from 'rollup-plugin-terser' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import replace from 'rollup-plugin-replace' | ||
|
||
import babel from 'rollup-plugin-babel' | ||
import fs from 'fs' | ||
|
||
const babelRc = JSON.parse(fs.readFileSync('./.babelrc')) | ||
|
||
const cjs = { | ||
exports: 'named', | ||
format: 'cjs', | ||
sourcemap: true | ||
} | ||
|
||
const esm = { | ||
format: 'esm', | ||
sourcemap: true | ||
const globals = { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'styled-components': 'styled', | ||
'@microlink/mql': 'mql' | ||
} | ||
|
||
const getCJS = override => ({ ...cjs, ...override }) | ||
const getESM = override => ({ ...esm, ...override }) | ||
|
||
const commonPlugins = [ | ||
const plugins = ({ compress = false }) => [ | ||
nodeResolve(), | ||
babel({ | ||
babelrc: false, | ||
externalHelpers: false, | ||
...babelRc | ||
}), | ||
commonjs(), | ||
filesize() | ||
compress && terser({ sourcemap: true }), | ||
filesize(), | ||
visualizer({ template: 'treemap' }), | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify('production') | ||
}) | ||
] | ||
|
||
const configBase = { | ||
input: './src/index.js', | ||
// \0 is rollup convention for generated in memory modules | ||
external: id => | ||
!id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/'), | ||
plugins: commonPlugins | ||
} | ||
|
||
const globals = { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'styled-components': 'styled' | ||
} | ||
|
||
const standaloneBaseConfig = { | ||
...configBase, | ||
const build = ({ file, format, name, exports }) => ({ | ||
input: './src/index.js', | ||
output: { | ||
file: 'dist/microlink.js', | ||
format: 'umd', | ||
exports: 'named', | ||
globals, | ||
name: 'microlink', | ||
sourcemap: true | ||
file, | ||
format, | ||
exports, | ||
name, | ||
globals | ||
}, | ||
external: Object.keys(globals) | ||
} | ||
external: Object.keys(globals), | ||
plugins: plugins({ compress: file.includes('.min.') }) | ||
}) | ||
|
||
const prodPlugins = [ | ||
replace({ | ||
'process.env.NODE_ENV': JSON.stringify('production') | ||
export default [ | ||
build({ | ||
format: 'umd', | ||
file: 'dist/microlink.js', | ||
name: 'microlink' | ||
}), | ||
build({ | ||
format: 'umd', | ||
file: 'dist/microlink.min.js', | ||
name: 'microlink' | ||
}), | ||
terser({ | ||
sourcemap: true | ||
build({ | ||
format: 'esm', | ||
file: 'dist/microlink.m.js', | ||
exports: 'named' | ||
}), | ||
visualizer({ template: 'treemap' }) | ||
build({ | ||
format: 'esm', | ||
file: 'dist/microlink.m.min.js', | ||
exports: 'named' | ||
}), | ||
build({ | ||
format: 'cjs', | ||
file: 'dist/microlink.cjs.js', | ||
exports: 'named' | ||
}), | ||
build({ | ||
format: 'cjs', | ||
file: 'dist/microlink.cjs.min.js', | ||
exports: 'named' | ||
}) | ||
] | ||
|
||
const standaloneProdConfig = { | ||
...standaloneBaseConfig, | ||
output: { | ||
...standaloneBaseConfig.output, | ||
file: 'dist/microlink.min.js' | ||
}, | ||
plugins: standaloneBaseConfig.plugins.concat(prodPlugins) | ||
} | ||
|
||
const serverConfig = { | ||
...configBase, | ||
output: [ | ||
getESM({ file: 'dist/microlink.m.js' }), | ||
getCJS({ file: 'dist/microlink.cjs.js' }) | ||
] | ||
} | ||
|
||
export default [standaloneProdConfig, serverConfig] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.