Last active
March 12, 2020 16:46
-
-
Save webstrand/8eeb6dc095652f5bc8df2d20065849ba to your computer and use it in GitHub Desktop.
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
import alias from "@rollup/plugin-alias"; | |
import commonjs from "@rollup/plugin-commonjs"; | |
import resolve from "@rollup/plugin-node-resolve"; | |
import typescript from "@rollup/plugin-typescript"; | |
import { createFilter } from "@rollup/pluginutils"; | |
import surplusCompiler from "surplus/compiler"; | |
function surplus({ include, exclude, sourceMap = false }) { | |
const filter = createFilter(include, exclude); | |
return { | |
name: "surplus", | |
transform(code, id) { | |
if(!filter(id)) return null; | |
const result = surplusCompiler.compile(code, sourceMap ? { sourcemap: "extract" } : false); | |
return { | |
code: sourceMap ? result.src : result, | |
map: sourceMap ? result.map : null | |
}; | |
} | |
}; | |
} | |
const plugins = () => [ | |
typescript({ include: [ "*.ts+(|x)", "**/*.ts+(|x)", "../src/events.ts" ], exclude: [ "*.d.ts", "**/*.d.ts" ] }), | |
// To disable surplus, remove this line | |
surplus({ include: [ "*.tsx", "**/*.tsx", "*.jsx", "**/*.jsx" ], sourceMap: true }), | |
alias({ | |
entries: [ | |
// Some modules don't resolve correctly to the browser version. | |
//{ find: "socket.io-client", replacement: "node_modules/socket.io-client/dist/socket.io.dev.js" }, | |
] | |
}), | |
resolve({ | |
// prefer "browser" files over "main" or "module" files. | |
browser: true, | |
preferBuiltins: false, | |
}), | |
commonjs({ | |
include: /node_modules/, | |
}), | |
]; | |
// Rollup can produce multiple bundles from a single config file, | |
// each element of the default exported array defines a single | |
// bundle. | |
// | |
// Files are included or excluded from each individual bundle | |
// depending on what the `input` file imports. | |
export default [ | |
{ | |
input: "src/client.ts", | |
output: { | |
format: "iife", | |
file: "dist/client.js", | |
name: "client", | |
sourcemap: true, | |
}, | |
plugins: plugins() | |
}, | |
{ | |
input: "src/server.tsx", | |
output: { | |
format: "iife", | |
file: "dist/server.js", | |
name: "server", | |
sourcemap: true, | |
}, | |
plugins: plugins() | |
}, | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment