mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Install scripts, build app with rollup & configurable mirror app id
This commit is contained in:
34
app/rollup/no-memcpy-plugin.js
Normal file
34
app/rollup/no-memcpy-plugin.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import MagicString from 'magic-string';
|
||||
|
||||
const MEMCPY_REQUIRE_STRING = 'require("memcpy")';
|
||||
const REPLACEMENT_STRING = 'null';
|
||||
|
||||
// We're doing this because memcpy is an optional dependency of ByteBufferNB,
|
||||
// but Rollup doesn't understand optional dependencies and tries to use it.
|
||||
// We can't simply use memcpy, because it has native code for older versions of
|
||||
// Node and no longer builds!
|
||||
export default (variant) => {
|
||||
let mainId = null;
|
||||
|
||||
return {
|
||||
name: 'no-memcpy-plugin'
|
||||
, transform: (code, id) => {
|
||||
if (id.endsWith('ByteBufferNB.js')) {
|
||||
const start = code.indexOf(MEMCPY_REQUIRE_STRING);
|
||||
|
||||
if (start >= 0) {
|
||||
const magicString = new MagicString(code);
|
||||
const end = start + MEMCPY_REQUIRE_STRING.length;
|
||||
magicString.overwrite(start, end, REPLACEMENT_STRING);
|
||||
|
||||
return {
|
||||
code: magicString.toString()
|
||||
, map: magicString.generateMap()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
app/rollup/rollup.config.js
Normal file
56
app/rollup/rollup.config.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import { resolve } from 'path'
|
||||
|
||||
import babel from 'rollup-plugin-babel'
|
||||
import builtins from 'rollup-plugin-node-builtins'
|
||||
import commonjs from 'rollup-plugin-commonjs'
|
||||
import json from 'rollup-plugin-json'
|
||||
import nodeResolve from 'rollup-plugin-node-resolve'
|
||||
|
||||
import noMemcpy from './no-memcpy-plugin'
|
||||
|
||||
export default options => {
|
||||
// TODO: Enabling this option presently doesn't work because castv2 proto
|
||||
// files aren't bundled, can be fixed with a couple of plugins
|
||||
const external = options.dependencies ? () => false : (id, parentId) => {
|
||||
if (!parentId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !!id.match(/^[^./].+$/)
|
||||
|| resolve(parentId, '..', id).includes('/node_modules/');
|
||||
};
|
||||
|
||||
return {
|
||||
external
|
||||
, input: './src/js/main.js'
|
||||
, plugins: [
|
||||
noMemcpy()
|
||||
, babel({
|
||||
exclude: [
|
||||
'node_modules/**'
|
||||
]
|
||||
, runtimeHelpers: true
|
||||
})
|
||||
, json()
|
||||
, builtins()
|
||||
, nodeResolve({
|
||||
module: true
|
||||
, jsnext: true
|
||||
, main: true
|
||||
, browser: false
|
||||
})
|
||||
, commonjs({
|
||||
// Protobuf detects itself running in Node by attempting to
|
||||
// require fs, so we better allow it...
|
||||
ignore: ['fs']
|
||||
})
|
||||
]
|
||||
, output: [
|
||||
{
|
||||
file: resolve(__dirname, '../../dist/app/app.js')
|
||||
, format: 'cjs'
|
||||
, sourcemap: options.sourcemap || false
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user