mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-26 08:11:17 +02:00
add prettier inside worker on shift-tab
This commit is contained in:
24
src/utils.js
24
src/utils.js
@@ -461,24 +461,14 @@ export function getFilenameFromUrl(url) {
|
||||
}
|
||||
|
||||
export function prettify(content, type = 'js') {
|
||||
const prettier = require('prettier/standalone');
|
||||
let plugins, parser;
|
||||
if (type === 'js') {
|
||||
parser = 'babylon';
|
||||
plugins = [require('prettier/parser-babylon')];
|
||||
} else if (type === 'css') {
|
||||
parser = 'css';
|
||||
plugins = [require('prettier/parser-postcss')];
|
||||
}
|
||||
|
||||
if (!parser) {
|
||||
return content;
|
||||
}
|
||||
const formattedContent = prettier.format(content, {
|
||||
parser,
|
||||
plugins
|
||||
const d = deferred();
|
||||
const worker = new Worker('/lib/prettier-worker.js');
|
||||
worker.postMessage({ content, type });
|
||||
worker.addEventListener('message', e => {
|
||||
d.resolve(e.data);
|
||||
worker.terminate();
|
||||
});
|
||||
return formattedContent || content;
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
if (window.IS_EXTENSION) {
|
||||
|
Reference in New Issue
Block a user