make rollup watch mode work

This commit is contained in:
nikek
2020-04-01 23:24:11 +02:00
parent e791907d1f
commit d4ac45b628
3 changed files with 22 additions and 57 deletions
+1 -1
View File
@@ -64,7 +64,7 @@
"react-scripts": "^3.4.1",
"recursive-readdir": "^2.2.2",
"replace-in-file": "^5.0.2",
"rollup": "^2.1.0",
"rollup": "^2.3.2",
"rollup-plugin-image-files": "^1.4.2",
"rollup-plugin-peer-deps-external": "^2.2.2",
"rollup-plugin-postcss": "^2.5.0",
+11 -25
View File
@@ -14,35 +14,21 @@
* limitations under the License.
*/
const rollup = require('rollup'); // "import" is not working for some reason...
import rollupConfig from './rollup.config';
import { rollup, watch, RollupWatchOptions, OutputOptions } from 'rollup';
import conf from './rollup.config';
import { Command } from 'commander';
import { run } from '../../helpers/run';
export default async (cmd: Command) => {
const inputOptions = {
input: rollupConfig.input,
plugins: rollupConfig.plugins,
};
const outputOptions = rollupConfig.output;
if (cmd.watch) {
await run('rollup -c -w');
// const watchOptions = {
// ...inputOptions,
// output: [outputOptions],
// watch: {
// include: ['src/**/*'],
// chokidar: true,
// },
// };
// const watcher = rollup.watch(watchOptions);
// watcher.on('event', (event: any) => {
// process.stdout.write(event);
// });
const watcher = watch(conf as RollupWatchOptions);
watcher.on('event', console.log);
await new Promise(() => {});
} else {
const bundle = await rollup.rollup(inputOptions);
await bundle.generate(outputOptions);
await bundle.write(outputOptions);
const bundle = await rollup({
input: conf.input,
plugins: conf.plugins,
});
await bundle.generate(conf.output as OutputOptions);
await bundle.write(conf.output as OutputOptions);
}
};