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

【typescript问题】entry为"xxx.vue?entry=true"的时候会报错 #28

Open
xiaomingplus opened this issue Oct 16, 2018 · 3 comments
Open

Comments

@xiaomingplus
Copy link

entry为"xxx.vue?entry=true"的时候会报错。如下图:
image

研究了一下,发现应该是给ts-loader传参数的时候有问题,ts-loader的appendTsSuffixTo参数期待的是一个正则表达式,但是用query的json形式无法把正则的参数正确传进去,可否把传参切换成options的形式?

临时解决这个问题的话,可以在ts-loader的入口,加一句:

options.appendTsSuffixTo = [/\.vue$/]

写死这个参数。

@Hanks10100
Copy link
Contributor

你已经给出了解法,在配置 ts-loader 的时候加上 appendTsSuffixTo 是个比较合理的用法。

另外,最好是用 js 或者 ts 文件为入口文件吧,不要直接用 .vue 文件当入口, .vue 只是组件,页面上总要有一句 new Vue 来触发渲染。(或者在 .vue 文件里加上 el 属性,这样就不需要加 entry=true 了)

@xiaomingplus
Copy link
Author

你已经给出了解法,在配置 ts-loader 的时候加上 appendTsSuffixTo 是个比较合理的用法。

另外,最好是用 js 或者 ts 文件为入口文件吧,不要直接用 .vue 文件当入口, .vue 只是组件,页面上总要有一句 new Vue 来触发渲染。(或者在 .vue 文件里加上 el 属性,这样就不需要加 entry=true 了)

但是问题是weex-loader现在在合并loader的时候用的还是webpack1.0的做法,用query来传参,而ts-loader的这个appendTsSuffixTo参数又无法用query stringify来传参。所以我觉得好的思路是weex-loader在合并loader的时候,通通改成 用options来传参,这样才能适配越来越多的库。

想用entry=true主要是因为weex端和web端同时在构建,想尽可能减少两端不一致的写法,不单独为weex加文件。

@Hanks10100
Copy link
Contributor

在 web 上使用 js 或者 ts 为入口文件也是最佳实践。
用 TypeScript 的时候 weex-loaderts-loader 的配置可以参考这个仓库。 https://github.com/Hanks10100/weex-typescript-example

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

2 participants