/
dimamir
/
magic-string
Обзор
Документация
Войти
/
dimamir
/
magic-string
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
example/build.js
35 строк
847 B
yoho
docs: example dump file error (#256)
19 авг 2023, 18:20
Не верифицирован
19 авг 2023, 18:20
962192c
Код
Авторство
О чём код?
var fs = require( 'fs' ), MagicString = require( '../' ); process.chdir( __dirname ); fs.readFile( 'app.source.js', function ( err, result ) { var source, magicString, pattern = /foo/g, match, transpiled, map; if ( err ) throw err; source = result.toString(); magicString = new MagicString( result.toString() ); while ( match = pattern.exec( source ) ) { magicString.overwrite( match.index, match.index + 3, 'answer' ); } transpiled = magicString.toString() + '\n//# sourceMappingURL=app.js.map'; map = magicString.generateMap({ file: 'app.js.map', source: 'app.source.js', includeContent: true, hires: true }); fs.writeFileSync( 'app.js', transpiled ); fs.writeFileSync( 'app.js.map', JSON.stringify(map) ); fs.writeFileSync( 'app.inlinemap.js', transpiled + '\n//#sourceMappingURL=' + map.toUrl() ); });