skinview3d/tools/rollup-util.js

77 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-07-06 09:26:01 +02:00
import { uglify } from "rollup-plugin-uglify";
2018-01-06 11:47:07 +01:00
import babel from "rollup-plugin-babel";
2018-01-15 11:46:30 +01:00
import resolve from "rollup-plugin-node-resolve";
2018-02-10 07:05:07 +01:00
import license from "rollup-plugin-license";
import fs from "fs";
2018-01-15 11:46:30 +01:00
2017-10-02 15:29:41 +02:00
let buildType = config => {
let options = {
2018-01-06 11:47:07 +01:00
input: "src/skinview3d.js",
2018-01-15 11:46:30 +01:00
output: [],
2018-02-10 07:05:07 +01:00
external: [
2018-01-15 11:46:30 +01:00
"three"
],
plugins: [
resolve()
]
2018-01-06 12:31:34 +01:00
};
switch (config.format) {
case "umd":
options.output.push({
2018-01-06 11:47:07 +01:00
format: "umd",
name: "skinview3d",
2018-01-15 12:06:46 +01:00
file: `build/skinview3d${config.postfix}.js`,
indent: "\t",
sourcemap: true,
globals: {
"three": "THREE"
}
2018-01-06 12:31:34 +01:00
});
break;
case "es":
options.output.push({
2018-01-06 11:47:07 +01:00
format: "es",
2018-01-15 12:06:46 +01:00
file: `build/skinview3d${config.postfix}.js`,
indent: "\t",
sourcemap: true,
2018-01-06 12:31:34 +01:00
});
break;
default:
throw `Unknown format: ${config.format}`;
}
2017-10-02 15:29:41 +02:00
if (config.babel) {
options.plugins.push(
babel({
2018-01-06 12:31:34 +01:00
exclude: "node_modules/**"
2017-10-02 15:29:41 +02:00
})
);
}
2018-01-06 12:31:34 +01:00
2017-10-02 15:29:41 +02:00
if (config.uglify) {
options.plugins.push(
uglify({
output: {
2018-01-06 12:31:34 +01:00
comments: "some"
2017-10-02 15:29:41 +02:00
}
2018-02-02 11:37:35 +01:00
})
2017-10-02 15:29:41 +02:00
);
}
2018-02-10 07:05:07 +01:00
options.plugins.push(
license({
sourcemap: true,
banner: `
skinview3d (https://github.com/to2mbn/skinview3d)
${fs.readFileSync("LICENSE").toString()}
`
})
);
2017-10-02 15:29:41 +02:00
return options;
};
export { buildType };