-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from Drevoed/feature/rollup-mjs-build
- Loading branch information
Showing
8 changed files
with
1,658 additions
and
2,716 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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const { resolve: resolvePath } = require('path'); | ||
|
||
module.exports = (api) => { | ||
api && api.cache && api.cache.never && api.cache.never(); | ||
// const env = api.cache(() => process.env.NODE_ENV) | ||
return generateConfig(meta, babelConfig); | ||
}; | ||
|
||
const meta = { | ||
isEsm: true, | ||
}; | ||
|
||
function generateConfig(meta, config = babelConfig) { | ||
const result = {}; | ||
for (const key in config) { | ||
const value = config[key]; | ||
result[key] = typeof value === 'function' ? value(meta) : value; | ||
} | ||
return result; | ||
} | ||
|
||
module.exports.generateConfig = generateConfig; | ||
|
||
const aliases = { | ||
effector: { | ||
esm: 'effector/effector.mjs', | ||
}, | ||
forest: { | ||
esm: 'forest/forest.mjs', | ||
}, | ||
stylis: { | ||
esm: 'stylis/dist/stylis.mjs', | ||
}, | ||
}; | ||
|
||
const babelConfig = { | ||
presets: ['@babel/preset-env', '@babel/preset-typescript'], | ||
plugins(meta) { | ||
const alias = parseAliases(meta, aliases); | ||
return [ | ||
[ | ||
require.resolve('./babel-plugin.js'), | ||
{ allowedModules: '../foliage', debug: false }, | ||
], | ||
['effector/babel-plugin', { addLoc: true }], | ||
[ | ||
'babel-plugin-module-resolver', | ||
{ | ||
alias, | ||
loglevel: 'silent', | ||
}, | ||
], | ||
]; | ||
}, | ||
}; | ||
|
||
// eslint-disable-next-line sonarjs/cognitive-complexity | ||
function parseAliases(meta, object) { | ||
const result = {}; | ||
for (const key in object) { | ||
const value = object[key]; | ||
if (typeof value === 'function') { | ||
const name = value(meta); | ||
if (name === undefined || name === null) continue; | ||
result[key] = name; | ||
} else if (typeof value === 'object' && value !== null) { | ||
const name = applyPaths(value); | ||
if (name === undefined || name === null) continue; | ||
result[key] = name; | ||
} else { | ||
const name = value; | ||
if (name === undefined || name === null) continue; | ||
result[key] = name; | ||
} | ||
} | ||
return result; | ||
|
||
function applyPaths(paths) { | ||
if (meta.isEsm) return paths.esm; | ||
return paths.default; | ||
} | ||
} | ||
|
||
module.exports.getAliases = (metadata = meta) => | ||
parseAliases(metadata, aliases); |
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { resolve } from 'path'; | ||
import pluginResolve from '@rollup/plugin-node-resolve'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import { babel } from '@rollup/plugin-babel'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import typescript from '@rollup/plugin-typescript'; | ||
import Package from './package.json'; | ||
|
||
const extensions = ['.tsx', '.ts', '.js', '.json']; | ||
|
||
function createBuild(input, format) { | ||
return { | ||
input: resolve(__dirname, `src/${input}.ts`), | ||
output: { | ||
file: `${input}.${format === 'esm' ? 'mjs' : 'js'}`, | ||
format, | ||
plugins: [terser()], | ||
sourcemap: true, | ||
}, | ||
plugins: [ | ||
commonjs(), | ||
pluginResolve({ extensions }), | ||
typescript({ | ||
tsconfig: './tsconfig.build.json', | ||
}), | ||
babel({ | ||
babelHelpers: 'bundled', | ||
extensions, | ||
skipPreflightCheck: true, | ||
babelrc: false, | ||
...require('./babel.config').generateConfig({ | ||
isEsm: format === 'esm', | ||
}), | ||
}), | ||
], | ||
external: [ | ||
'forest/forest.mjs', | ||
'effector/effector.mjs', | ||
'stylis/dist/stylis.mjs', | ||
].concat( | ||
Object.keys(Package.peerDependencies), | ||
Object.keys(Package.dependencies), | ||
), | ||
}; | ||
} | ||
|
||
const inputs = ['index']; | ||
const formats = ['cjs', 'esm']; | ||
|
||
const config = inputs.flatMap((i) => formats.map((f) => createBuild(i, f))); | ||
|
||
export default config; |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.