Skip to content

Commit

Permalink
wip: remove debugger, define vue flags in plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 19, 2020
1 parent 50ef75e commit 31a9c90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 9 additions & 0 deletions packages/plugin-vue/src/index.ts
Expand Up @@ -67,6 +67,15 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin {

handleHotUpdate,

config(config) {
// provide default values for vue runtime esm defines
config.define = {
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
...config.define
}
},

configResolved(config) {
options = {
...options,
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-vue/src/main.ts
Expand Up @@ -90,15 +90,15 @@ export async function transformMain(
output.push('export default _sfc_main')

// HMR
if (devServer) {
// check if the template is the only thing that changed
if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) {
output.push(`export const _rerender_only = true`)
}
if (devServer && !isProduction) {
output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`)
output.push(
`__VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)`
)
// check if the template is the only thing that changed
if (prevDescriptor && isOnlyTemplateChanged(prevDescriptor, descriptor)) {
output.push(`export const _rerender_only = true`)
}
output.push(
`import.meta.hot.accept(({ default: updated, _rerender_only }) => {`,
` if (_rerender_only) {`,
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/template.ts
Expand Up @@ -19,7 +19,7 @@ export function transformTemplateAsModule(
const result = compile(code, descriptor, options, pluginContext)

let returnCode = result.code
if (options.devServer) {
if (options.devServer && !options.isProduction) {
returnCode += `\nimport.meta.hot.accept(({ render }) => {
__VUE_HMR_RUNTIME__.rerender(${JSON.stringify(descriptor.id)}, render)
})`
Expand Down

0 comments on commit 31a9c90

Please sign in to comment.