-
Notifications
You must be signed in to change notification settings - Fork 546
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
<script setup>
#227
<script setup>
#227
Conversation
I have some concerns that it will block tree-shake. It is difficult to analyze whether a var has been used in the template <template>
<div></div>
</template>
<script>
// Can you know where the lodash is used?
import _ from "lodash"
</script> |
Does auto-exposing imported vue components mean that PascalCase is now required in SFCs? Consider the following: <script setup>
import MyDatePicker from './my-date-picker.vue';
</script>
<template>
<!-- This is obvious -->
<MyDatePicker />
<!-- Will this still work? -->
<my-date-picker />
</template> Right now the vue style guide says this is "strongly recommended", but not required. The kebab-casing is something I've seen in plenty of code I've reviewed. As people refactor, this might be something worth calling out explicitly. |
@mgdodge I believe they will work for both styles in template. |
Great that you have split the RFC! This part is much less controversial and might move forward faster. First a general question:
I like the local component example but how does that work exactly?
I note that this closes the door to MVVM style testing practices, which encourages unit testing a component without actually executing any UI. Another concern: when it comes to debugging, will we have easy access to instance data? Or will it be in a form that is really hard to get to?
That felt ok when you had the other I don't have a great suggestion here but... maybe put it in a
I ❤️ this, so much better than the current code. How will it work for more advanced scenarios, e.g. if we want to tap into prop validation? I assume we will use the JS props syntax, will it still declare the props type automatically as it does today?
Surely you mean this won't work: import T from "types"
declare const props: T But surely this would, right? import T from "types
declare const props: { foo: T }
It's a bit weird to reference variables across scripts blocks but hey. My understanding of the RFC is that components defined in How can I import the component that is defined in the
I was really torn about that one and changed my mind several time, but I agree it's weird and tricky. There are some bits that would be tricky technically, and for users you couldn't really reference globals in other The question: what happens when your component gets really big? is still relevant. I still feel differently about the ref part, but that's another RFC now.
I'm still wary about this, because even if you don't use this RFC, you probably still use Vetur. Can you confirm that the following is a good understanding of your plans? So what the IDE plugin needs to do in the
That would seem a reasonable complexity and it wouldn't negatively impact the coding experience. |
Re tree-shaking: we definitely can reverse prune the exposed bindings because we do know what exactly the template uses during the template compilation process. The only downside is maybe we'll have to process the script twice - but we can cache the previous AST and only redo code generation. So yeah, short answer is this is fixable (just some extra implementation cost). |
It can keep supporting kebab-case. |
I haven't really benched this, but my intuition would be non-trivial and it scales with the number of bindings used in the template.
During the script compile it generates binding metadata, and the components will be listed as setup bindings as well. When compiling the template, we will check if a component is exposed in setup and directly use the setup binding instead of attempting to resolve it at runtime.
Yes.
Yes.
No. Directives will still need to use
With explicit
You can still get a hold of the internal instance for debugging since you control the code.
This is a good question to which I don't have a good answer for yet. But in general if you use TS declarations you have less need for manual validators anyway. For imported types: import T from "types"
declare const props: { foo: T } Yes the above will work, but it will only generate a type-less runtime prop declaration since the compiler won't be able to trace the exact type of
It works the same since it compiles down to
Yes, your understanding is largely on point. |
Unfortunate, is there really nothing you can do about this? Maybe when encountering
Not really:
It's not about controlling the code: I was afraid that after transformation everything would be local scope captures in a render function, which would be quite less practical in debug. You need to be in the right scope to get a peek with the debugger. Today, with Vue devtools plugin or even without, if you can grab the component instance from Vue you can see and modify its internal state.
Well yes but same-file references to the component shouldn't be compiled to an const _default = { setup() { } }
export default _default
// Code that imported default from itself would then reference _default constant. |
I hope snake_case_style works well too, because it is convenient for custom snippets and looks very nice. import ${1:my_header_left} from "@/components/${1:my_header_left}.vue" Although the underscore(_) character is not well highlighted in the standard template scope, it works well in the template lang="pug/jade" scope. |
some questions: in this Child.vue I can explicitly return say function or not
in app.vue i can use the function say if child component return it
but in setup script, the say function i don't use in template, Will it be exported?
|
You don't need to do that. All variables are available to template but closed to external access by default. |
Update: https://github.com/vuejs/vue-next/tree/ref-sugar now implements an option for Some notes:
|
Ask a question, can it receive |
@yyx990803 I think we can use const hotReloadRender = ref(function() {
return h('div', unref(count))
})
export default {
setup() {
const count = ref(0)
const inc = () => count.value++
return () => {
let render
eval('render =' + hotReloadRender.value.toString())
return render()
}
}
} |
Since we're aggressively trimming syntax down anyway, why not go all-out and make it possible to write js/ts directly at the root? import { ref, useProps, useEmit } from 'vue'
const { message } = useProps<{ message: string }>()
const emit = useEmit<{ change: number }>()
const count = ref(0)
const inc = () => {
count.value++
emit('change', count.value)
}
<template>
<p>
{{ count }} {{ message }}
</p>
<button @click="inc">Increment</button>
</template> The I'm not gonna lie though, my true hope is to one day be able to write vue templates (not jsx) inline anywhere and have them extracted and compiled as we've come to expect: import { ref, createComponent } from 'vue'
const Counter = createComponent<{
message: string,
emit: {
change: number,
},
}>(({ message }, emit) => {
const count = ref(0)
const inc = () => {
count.value++
emit('change', count.value)
}
const { redText } = (
<style>
.redText {
color: 'red'
}
</style>
)
return (
<template>
<p :class="redText">
{{ count }} {{ message }}
</p>
<button @click="inc">Increment</button>
</template>
)
}) |
I do think that the
Since a similar technique is proposed for the For me, these functions change |
@vberlier Vue SFC is defined as using HTML syntax with script embedded in it. This is what allows style blocks, custom blocks, and the current parser/tooling is all built upon that assumption. Your proposal flips it the other way around. By definition, it's not SFC anymore. If you want to make |
It is a workaround. However, functions like
IDE support should be trivial because Current
As explained above... they can't be actual VCA functions so it may be confusing when people realize they are just compiler hints. |
To clarify what I mean by export default {
setup(props) {
// props must already be resolved before useProps is even called!
useProps({
foo: String
})
}
} So we have to hoist it out: export default {
// argument of useProps hoisted here
props: {
foo: String
},
setup(props) {
// ...
}
} But what if the user tries to do something like this? import { useProps } from 'vue'
import { useSomething } from './utils'
useProps({
foo: useSomething() ? String : Number
}) Note this will compile and run because Technically Finally, I think such cases should be extremely rare in production because 99% of props declarations are probably static... so maybe |
That's a good point, didn't think of that.
Yep, this is what I meant wih "using either a compile time loader or a runtime change of Although: if |
Played with the What if we consolidate it down to a single function: import { useSetupContext } from 'vue'
const { props, emit, slots, attrs } = useSetupContext({
props: {
foo: String
},
emits: ['foo', 'bar']
}) With type-only declarations: import { useSetupContext } from 'vue'
const { props, emit, slots, attrs } = useSetupContext<{
props: { foo: string },
emit: (e: 'foo' | 'bar') => void
}>() The argument of |
Would the following work (if import { composableProps } from "./my-composable";
const { composableProps } = useSetupContext({
props: {
...xProps
}
}) or even import { composablePropsFn } from "./my-composable";
const { composablePropsFn } = useSetupContext({
props: {
...xProps({ someOverride: 1 })
}
}) This is a pattern I see emerging for composables (I think this is the best pattern for this use-case) and I think it may become quite common as a replacement for mixins. See for example https://www.notion.so/Composables-0574a105b61c4da1bc0993c6bcb59aed. |
@Benoit-Vasseur what stops you from refactoring the privateFunction and public function into another file and exporting only the public function? |
I'd made similar comments in #222 which seemed to be well received by some, before this issue/feature was split off of it. I chose to use unit tests for my example, which was a contentious topic by itself and won't be discussed further here. Separating those private functions out into a separate file is not always desirable, so let's not suggest using composition when it's not helpful/needed. The desire to explicitly declare which values were "public" seems to be alive and well. The way I read the last few comments on this, Since script setup has shipped, I doubt there's enough value here to introduce a breaking change - That being said, I have yet to use |
@mgdodge what you say that not everything can be extracted away is absolutely valid, but i personally have not faced a scenario as you said regarding private and public function. aside from this, as you say, script setup is out and we cannot make large breaking change, although i completely agree with design decisions made regarding script setup. another point in your message that i have to point is that defineExpose does compile away, but is not noop! and is not only for documentation. it changes what properties are accessible from the vue component object, for example when you asisgn it to a ref. also, in the recent talks @yyx990803 has made, i think the ref sugars are useable in every file if i'm not mistaken. |
I definitively can do that yes. I just point that the setup script drop a "basic standard JS feature" => the return ^^ |
@Benoit-Vasseur practically, the script setup does not seem to be in a function, so having a return might surprise some users |
I apologize for wording my prior comment in a way that suggests The direction that |
@Benoit-Vasseur I'm a strong -1 on this. One of the original motivation for the script setup syntax is precisely to get rid of the redundant return statement. Edit: motivation in original RFC https://github.com/vuejs/rfcs/blob/sfc-improvements/active-rfcs/0000-sfc-script-setup.md#motivation |
@vberlier I also thought of that. Because in Options API, template could access anything from |
How can I use JSX with script setup ? |
<script lang="tsx">
export default defineComponent({
render() {
return <div> Hello </div>
}
})
</script> |
but cant use script-setup and jsx... |
@yyx990803 Do you have any plans to support 【script-setup-render】 grammar in the future。That is not supported by the website... |
If you are writing a render function then you don't even need SFC or |
|
diff --git a/README.md b/README.md index 8faad38..882547e 100644 --- a/README.md +++ b/README.md @@ -1,132 +1,21 @@ -# WebExtension Vite Starter +# Fussy history search -A [Vite](https://vitejs.dev/) powered WebExtension ([Chrome](https://developer.chrome.com/docs/extensions/reference/), [FireFox](https://addons.mozilla.org/en-US/developers/), etc.) starter template. - -<p align="center"> -<sub>Popup</sub><br/> -<img width="655" src="https://user-images.githubusercontent.com/11247099/126741643-813b3773-17ff-4281-9737-f319e00feddc.png"><br/> -<sub>Options Page</sub><br/> -<img width="655" src="https://user-images.githubusercontent.com/11247099/126741653-43125b62-6578-4452-83a7-bee19be2eaa2.png"><br/> -<sub>Inject Vue App into the Content Script</sub><br/> -<img src="https://user-images.githubusercontent.com/11247099/130695439-52418cf0-e186-4085-8e19-23fe808a274e.png"> -</p> +A very simple Chrome extension that enables fuzzy search of browsing histories. ## Features -- ⚡️ **Instant HMR** - use **Vite** on dev (no more refresh!) -- 🥝 Vue 3 - Composition API, [`<script setup>` syntax](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md) and more! -- 💬 Effortless communications - powered by [`webext-bridge`](https://github.com/antfu/webext-bridge) and [VueUse](https://github.com/antfu/vueuse) storage -- 🍃 [Windi CSS](https://windicss.org/) - on-demand CSS utilities -- 🦾 [TypeScript](https://www.typescriptlang.org/) - type safe -- 📦 [Components auto importing](./src/components) -- 🌟 [Icons](./src/components) - Access to icons from any iconset directly -- 🖥 Content Script - Use Vue even in content script -- 🌍 WebExtension - isomorphic extension for Chrome, Firefox, and others -- 📃 Dynamic `manifest.json` with full type support - -## Pre-packed - -### WebExtension Libraries - -- [`webextension-polyfill`](https://github.com/mozilla/webextension-polyfill) - WebExtension browser API Polyfill with types -- [`webext-bridge`](https://github.com/antfu/webext-bridge) - effortlessly communication between contexts - -### Vite Plugins - -- [`unplugin-auto-import`](https://github.com/antfu/unplugin-auto-import) - Directly use `browser` and Vue Composition API without importing -- [`unplugin-vue-components`](https://github.com/antfu/vite-plugin-components) - components auto import -- [`unplugin-icons`](https://github.com/antfu/unplugin-icons) - icons as components - - [Iconify](https://iconify.design) - use icons from any icon sets [🔍Icônes](https://icones.netlify.app/) -- [`vite-plugin-windicss`](https://github.com/antfu/vite-plugin-windicss) - WindiCSS support - -### Vue Plugins - -- [VueUse](https://github.com/antfu/vueuse) - collection of useful composition APIs - -### UI Frameworks - -- [Windi CSS](https://github.com/windicss/windicss) - next generation utility-first CSS framework - -### Coding Style - -- Use Composition API with [`<script setup>` SFC syntax](vuejs/rfcs#227) -- [ESLint](https://eslint.org/) with [@antfu/eslint-config](https://github.com/antfu/eslint-config), single quotes, no semi - -### Dev tools - -- [TypeScript](https://www.typescriptlang.org/) -- [pnpm](https://pnpm.js.org/) - fast, disk space efficient package manager -- [esno](https://github.com/antfu/esno) - TypeScript / ESNext node runtime powered by esbuild -- [npm-run-all](https://github.com/mysticatea/npm-run-all) - Run multiple npm-scripts in parallel or sequential -- [web-ext](https://github.com/mozilla/web-ext) - Streamlined experience for developing web extensions - -## Use the Template - -### GitHub Template - -[Create a repo from this template on GitHub](https://github.com/antfu/vitesse-webext/generate). - -### Clone to local - -If you prefer to do it manually with the cleaner git history - -> If you don't have pnpm installed, run: npm install -g pnpm - -```bash -npx degit antfu/vitesse-webext my-webext -cd my-webext -pnpm i -``` - -## Usage - -### Folders - -- `src` - main source. - - `contentScript` - scripts and components to be injected as `content_script` - - `background` - scripts for background. - - `components` - auto-imported Vue components that shared in popup and options page. - - `styles` - styles shared in popup and options page - - `manifest.ts` - manifest for the extension. -- `extension` - extension package root. - - `assets` - static assets. - - `dist` - built files, also serve stub entry for Vite on development. -- `scripts` - development and bundling helper scripts. - -### Development - -```bash -pnpm dev -``` - -Then **load extension in browser with the `extension/` folder**. - -For Firefox developers, you can run the following command instead: - -```bash -pnpm start:firefox -``` - -`web-ext` auto reload the extension when `extension/` files changed. - -> While Vite handles HMR automatically in the most of the case, [Extensions Reloader](https://chrome.google.com/webstore/detail/fimgfedafeadlieiabdeeaodndnlbhid) is still recommanded for cleaner hard reloading. - -### Build - -To build the extension, run - -```bash -pnpm build -``` +- ⚡️ Fuzzy search your browsing history. powered by [Fuse.js](https://fusejs.io/) +- 🔐 All processing is done within the browser. No history data will be sent to the any server. -And then pack files under `extension`, you can upload `extension.crx` or `extension.xpi` to appropriate extension store. +## Demo -## Credits +https://user-images.githubusercontent.com/11070996/147921381-500b1045-c544-4938-bc5f-f88759cc415b.mp4 -![](https://user-images.githubusercontent.com/11247099/127029137-6b5ad5db-76c4-4061-86ff-489911a8adfb.png) +## install -This template is originally made for the [volta.net](https://volta.net) browser extension. +// TODO -## Variations +I am currently in the process of submitting an extension to the public. -This is a variant of [Vitesse](https://github.com/antfu/vitesse), check out the [full variations list](https://github.com/antfu/vitesse#variations). +## Contributing +Contributions are welcome 🎉 We accept contributions via Pull Requests. diff --git a/package.json b/package.json index e9de3f1..6061c11 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "vitesse-webext", - "displayName": "Vitesse WebExt", + "name": "fussy-histoty-search", + "displayName": "Fussy history search", "version": "0.0.1", - "description": "[description]", + "description": "A very simple Chrome extension that enables fuzzy search of browsing histories.", "private": true, "scripts": { "dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*",
I got an error message that brought me to this pull request. For anyone else that is the same, here is how you use
|
app.js:2 Uncaught SyntaxError: Unexpected token '<' le probleme c'est quoi au juste |
app.js:2 Uncaught SyntaxError: Unexpected token '<' |
@Blaisepasca Please provide a reproduction and also you can probably open a new issue. |
@Blaisepasca this PR was already merged 3 years ago. |
…S module exports. If you are using a previous version of <script setup>, please consult the updated RFC at vuejs/rfcs#227.
- new `<script setup>` vuejs/rfcs#227 - new `<style>` variable injection vuejs/rfcs#231 Requires a version of `@vue/compiler-sfc` that supports the above features.
…p> cannot contain ES module exports. If you are using a previous version of <script setup>, please consult the updated RFC at vuejs/rfcs#227.
This PR separates the
<script setup>
as proposed in #222 from theref:
sugar so it can be discussed and advanced on its own. It also has incorporated edits based on feedbacks in #222 that are specifically related to<script setup>
.Rendered