/
ashipov
/
react
Обзор
Документация
Войти
/
ashipov
/
react
Код
Запросы
0
Задачи 2.0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
scripts/rollup/plugins/closure-plugin.js
41 строка
1 KB
Andrew Clark
Run Closure on non-minified prod builds, too (#28827)
19 апр 2024, 21:22
Не верифицирован
19 апр 2024, 21:22
0e0b693
Код
Авторство
О чём код?
'use strict'; const ClosureCompiler = require('google-closure-compiler').compiler; const {promisify} = require('util'); const fs = require('fs'); const tmp = require('tmp'); const writeFileAsync = promisify(fs.writeFile); function compile(flags) { return new Promise((resolve, reject) => { const closureCompiler = new ClosureCompiler(flags); closureCompiler.run(function (exitCode, stdOut, stdErr) { if (!stdErr) { resolve(stdOut); } else { reject(new Error(stdErr)); } }); }); } module.exports = function closure(flags = {}) { return { name: 'scripts/rollup/plugins/closure-plugin', async renderChunk(code, chunk, options) { const inputFile = tmp.fileSync(); // Tell Closure what JS source file to read, and optionally what sourcemap file to write const finalFlags = { ...flags, js: inputFile.name, }; await writeFileAsync(inputFile.name, code, 'utf8'); const compiledCode = await compile(finalFlags); inputFile.removeCallback(); return {code: compiledCode}; }, }; };