Code split and load prettier dynamically (#471)

* code split and load prettier dynamically;

* move prettier to dependencies
main
Michael Fix 6 years ago committed by GitHub
parent 4f7938d931
commit 0d2f2f4444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,12 +31,11 @@ class Settings extends React.Component {
} }
format() { format() {
try { return formatCode(this.props.code)
const newCode = formatCode(this.props.code) .then(this.props.onChange.bind(this, 'code'))
this.props.onChange('code', newCode) .catch(() => {
} catch (e) { // create toast here in the future
// pass, create a toast here in the future. })
}
} }
render() { render() {

@ -1,6 +1,4 @@
import morph from 'morphmorph' import morph from 'morphmorph'
import prettier from 'prettier/standalone'
import babylonParser from 'prettier/parser-babylon'
const KEY = 'CARBON_STATE' const KEY = 'CARBON_STATE'
@ -43,10 +41,14 @@ export const fileToDataURL = blob =>
reader.readAsDataURL(blob) reader.readAsDataURL(blob)
}) })
export const formatCode = code => export const formatCode = async code => {
prettier.format(code, { const prettier = await import('prettier/standalone')
const babylonParser = await import('prettier/parser-babylon')
return prettier.format(code, {
parser: 'babylon', parser: 'babylon',
plugins: [babylonParser], plugins: [babylonParser],
semi: false, semi: false,
singleQuote: true singleQuote: true
}) })
}

@ -39,6 +39,7 @@
"next": "^6.0.3", "next": "^6.0.3",
"next-offline": "^2.9.0", "next-offline": "^2.9.0",
"now-logs": "^0.0.7", "now-logs": "^0.0.7",
"prettier": "^1.8.1",
"puppeteer": "1.7.0", "puppeteer": "1.7.0",
"react": "16.3.*", "react": "16.3.*",
"react-click-outside": "^3.0.0", "react-click-outside": "^3.0.0",
@ -67,7 +68,6 @@
"husky": "^0.14.3", "husky": "^0.14.3",
"lint-staged": "^7.0.4", "lint-staged": "^7.0.4",
"now": "^11.1.7", "now": "^11.1.7",
"prettier": "^1.8.1",
"webpack": "^3.10.0" "webpack": "^3.10.0"
}, },
"lint-staged": { "lint-staged": {

Loading…
Cancel
Save