Skip to content

Instantly share code, notes, and snippets.

@wickkidd
Last active December 14, 2020 15:57
Show Gist options
  • Save wickkidd/028ff52b20d0a3e06739125c4120bc25 to your computer and use it in GitHub Desktop.
Save wickkidd/028ff52b20d0a3e06739125c4120bc25 to your computer and use it in GitHub Desktop.
import alias from '@rollup/plugin-alias'
import analyze from 'rollup-plugin-analyzer'
import requireContext from 'rollup-plugin-require-context'
import sass from 'rollup-plugin-sass'
import typescript from 'rollup-plugin-typescript2'
import VuePlugin from 'rollup-plugin-vue'
import fs from 'fs'
import path from 'path'
import pkg from './package.json'
let inputFilesObj = {}
function getInputFiles(dir, maxDepth, curDepth = 0) {
if (curDepth > maxDepth) return
fs.readdirSync(dir).forEach(file => {
const filePath = path.join(dir, file)
const stat = fs.statSync(filePath)
if (stat.isDirectory()) {
getInputFiles(filePath, maxDepth, curDepth + 1)
} else if (file === 'index.ts') {
inputFilesObj[path.basename(path.dirname(filePath))] = filePath
}
})
}
getInputFiles('src/components', 1)
const commonConfig = {
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
'lodash/debounce',
'lodash/get',
'lodash/lowerFirst',
'lodash/pullAllBy',
'lodash/throttle',
'lodash/uniqBy'
],
plugins: [
requireContext(),
alias({
resolve: ['.js', '.ts', '.vue'],
entries: {
'@': path.resolve(__dirname, 'src'),
'@components': path.resolve(__dirname, 'src/components'),
'@directives': path.resolve(__dirname, 'src/directives'),
'@helpers': path.resolve(__dirname, 'src/helpers'),
'@mixins': path.resolve(__dirname, 'src/mixins'),
'@plugins': path.resolve(__dirname, 'src/plugins')
}
}),
VuePlugin({
data: { scss: '@import "./src/styles/settings/index.scss";' } // in vue.config.js this is css.loaderOptions.sass.data
}),
sass(),
typescript({ tsconfig: 'tsconfig.json' })//,
// analyze({ summaryOnly: true })
]
}
// Every conceivable output during transition ;-)
export default [
{
input: 'src/components/index.js',
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true
},
{
file: pkg.module,
format: 'es',
sourcemap: true
}
],
...commonConfig
},
{
input: {
index: 'src/components/index.js',
...inputFilesObj
},
output: [
{
dir: 'lib/cjs',
format: 'cjs',
sourcemap: true
},
{
dir: 'lib/esm',
format: 'es',
sourcemap: true
}
],
...commonConfig
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment