Skip to content

feat: add prettify option #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ interface TemplateCompileOptions {
isProduction?: boolean // default: false
isFunctional?: boolean // default: false
optimizeSSR?: boolean // default: false

// Whether prettify compiled render function or not (development only)
// default: true
prettify?: boolean
}

interface TemplateCompileResult {
Expand Down
13 changes: 10 additions & 3 deletions lib/compileTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import assetUrlsModule, {
} from './templateCompilerModules/assetUrl'
import srcsetModule from './templateCompilerModules/srcset'

const prettier = require('prettier')
const consolidate = require('consolidate')
const transpile = require('vue-template-es2015-compiler')

Expand All @@ -21,6 +20,7 @@ export interface TemplateCompileOptions {
isProduction?: boolean
isFunctional?: boolean
optimizeSSR?: boolean
prettify?: boolean
}

export interface TemplateCompileResult {
Expand Down Expand Up @@ -103,7 +103,8 @@ function actuallyCompile(
transformAssetUrls,
isProduction = process.env.NODE_ENV === 'production',
isFunctional = false,
optimizeSSR = false
optimizeSSR = false,
prettify = true
} = options

const compile =
Expand Down Expand Up @@ -163,7 +164,13 @@ function actuallyCompile(
// mark with stripped (this enables Vue to use correct runtime proxy
// detection)
code += `render._withStripped = true`
code = prettier.format(code, { semi: false, parser: 'babylon' })

if (prettify) {
code = require('prettier').format(code, {
semi: false,
parser: 'babylon'
})
}
}

return {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy