Skip to content

Instantly share code, notes, and snippets.

@dux
Last active May 23, 2019 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dux/87ebec2deeb108d901531a5261d1cdd9 to your computer and use it in GitHub Desktop.
Save dux/87ebec2deeb108d901531a5261d1cdd9 to your computer and use it in GitHub Desktop.
multi file rollup config with coffeescript, svelte, react and livereload
import babel from 'rollup-plugin-babel'
import svelte from 'rollup-plugin-svelte'
import { scss } from '@kazzkiq/svelte-preprocess-scss';
import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import { terser } from 'rollup-plugin-terser'
import coffee from 'rollup-plugin-coffee-script'
import livereload from 'rollup-plugin-livereload'
const production = !process.env.ROLLUP_WATCH;
const extensions = ['.js', '.coffee']
class Config {
constructor(init) {
this.list = []
}
default(name) {
return {
input: `app/assets/${name}`,
output: {
sourcemap: false,
format: 'iife',
file: `public/assets/${name}`,
name: name,
},
plugins: [
coffee({exclude: 'node_modules/**'}),
nodeResolve({
browser: true,
extensions: extensions
}),
babel({
extensions: extensions
}),
commonjs({
extensions: extensions,
ignoreGlobal: true,
}),
production && terser()
]
}
}
add(name, func) {
let opts = this.default(name)
if (func) { func(opts) }
this.list.push(opts)
}
}
let config = new Config()
config.add('main.js', (cfg) => {
cfg.plugins.push(
livereload({ watch: './public/assets' })
)
})
config.add('main-react.js', (cfg) => {
cfg.output.globals = {
'react': 'React',
'react-dom':'ReactDOM'
}
cfg.external = [
"react",
"react-dom"
]
})
config.add('main-svelte.js', (cfg) => {
cfg.plugins.push(
svelte({
dev: !production,
preprocess: { style: scss() }
})
)
})
export default config.list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment