Skip to content
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

.vue文件打包后 const 等es6 语法未被babel转换 #29

Closed
lljj-x opened this issue Jan 18, 2021 · 1 comment
Closed

.vue文件打包后 const 等es6 语法未被babel转换 #29

lljj-x opened this issue Jan 18, 2021 · 1 comment

Comments

@lljj-x
Copy link
Owner

lljj-x commented Jan 18, 2021

lib中存在 const 等es6 语法未被babel转换

看起来像 vue plugin 生成的

image

@lljj-x
Copy link
Owner Author

lljj-x commented Jan 18, 2021

es6 未转换代码来源有两个部分:

.vue 文件需要通过 babel 处理

这里需要注意顺序,vue plugin 在前 babel 在后。

如下类似代码:

  /* style */
  const __vue_inject_styles__ = undefined;
  /* scoped */
  const __vue_scope_id__ = undefined;
  /* module identifier */
  const __vue_module_identifier__ = undefined;
  /* functional template */
  const __vue_is_functional_template__ = false;

解决:

babel({
    exclude: /node_modules\/(?!(@lljj)\/).*/,
    extensions: ['.js', '.vue'], // + .vue 文件
})

参考:rollup/rollup-plugin-babel#260

vue runtime helper 转换后的代码存在 const,如下

normalizeComponent 这个方法内,直接通过babel include 应该也可

如下类似代码:

function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
    if (typeof shadowMode !== 'boolean') {
        createInjectorSSR = createInjector;
        createInjector = shadowMode;
        shadowMode = false;
    }
    // Vue.extend constructor export interop.
    const options = typeof script === 'function' ? script.options : script;
 }
}

解决:

vue({
  normalizer: '~vue-runtime-helpers/dist/normalize-component.js'
})

参考:vuejs/rollup-plugin-vue#262 (comment)

@lljj-x lljj-x changed the title lib中存在 const 等es6 语法未被babel转换 .vue文件打包后 const 等es6 语法未被babel转换 Jan 18, 2021
lljj-x added a commit that referenced this issue Jan 18, 2021
@lljj-x lljj-x closed this as completed Jan 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant