用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/dvcrn/skills --skill phoenix-colocated-js命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Install and configure PostHog in an Elixir/Phoenix project, including backend SDK, runtime configuration, an app-owned analytics boundary, identity wiring, JS client assets, template wiring, Plug middleware, and verification. Use when adding PostHog analytics or event capture to an Elixir or Phoenix application.
Install and configure Sentry in an Elixir or Phoenix project using official modern defaults, including runtime DSN configuration, Sentry.LoggerHandler with log message capture and rate limiting, Sentry.PlugContext placement, Cowboy/Bandit server detection, Oban error reporting, PII scrubbing, source code packaging for releases, and verification. Use when adding Sentry error monitoring or updating Sentry setup in an Elixir codebase.
SwiftUI state management using @Observable Store containers (Observation framework, iOS 17+), @Environment injection, store composition, derived state, and async mutation patterns. Use when designing or reviewing Store architecture, migrating from ObservableObject/Combine, translating React hooks or React Query patterns to SwiftUI, or implementing shared app-wide state containers.
正在显示 SKILL.md
| name | phoenix-colocated-js |
| description | Use when we need an explanation of Phoenix.LiveView.ColocatedJS and how colocated JS is compiled and imported |
Phoenix.LiveView.ColocatedJS is a special HEEx :type that extracts arbitrary JavaScript from a co-located <script> tag at compile time. It generalizes colocated hooks: hooks are built on top of ColocatedJS, but you can also use it for things like web components, global listeners, or other module exports.
phoenix-colocated/my_app exposes your exports for bundlersDefine colocated JS in your HEEx template and optionally name the export:
<script :type={Phoenix.LiveView.ColocatedJS} name="MyWebComponent">
export default class MyWebComponent extends HTMLElement {
connectedCallback() {
this.innerHTML = "Hello, world!";
}
}
</script>
Then import it in your main JS entrypoint (for example assets/js/app.js):
import colocated from "phoenix-colocated/my_app";
customElements.define("my-web-component", colocated.MyWebComponent);
Notes:
name attribute controls the key on the manifest export (here MyWebComponent)name, the file is imported for side effects onlyPhoenix.LiveView.ColocatedHookDuring compilation, LiveView writes colocated JS into a phoenix-colocated directory inside your build path:
_build/$MIX_ENV/phoenix-colocated/
_build/$MIX_ENV/phoenix-colocated/my_app/
_build/$MIX_ENV/phoenix-colocated/my_app/index.js
_build/$MIX_ENV/phoenix-colocated/my_app/MyAppWeb.DemoLive/line_HASH.js
_build/$MIX_ENV/phoenix-colocated/my_dependency/MyDependency.Module/line_HASH.js
Key points:
phoenix-colocatedindex.js is the manifest you import from phoenix-colocated/my_appphoenix-colocated folder should not be committed to version controlFor Phoenix 1.8 apps using esbuild, the default config already points NODE_PATH at Mix.Project.build_path() so import "phoenix-colocated/my_app" works out of the box:
config :esbuild,
my_app: [
args:
~w(js/app.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.),
cd: Path.expand("../assets", __DIR__),
env: %{
"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]
}
]
If you use a different bundler, you must configure it so that phoenix-colocated is resolvable (for example via NODE_PATH, an alias, or a symlink into node_modules).
You can also change the target directory LiveView writes to:
config :phoenix_live_view, :colocated_js,
target_directory: Path.expand("../assets/node_modules/phoenix-colocated", __DIR__)
Warning: LiveView assumes full ownership of the :target_directory and may delete unmanaged files under it when compiling.
Colocated JS files are bundled like any other module. Imports from node_modules generally work without extra config, but imports into your app’s assets tree require care because colocated files live under _build.
Example:
def sha256(assigns) do
~H"""
<div id="sha-256" phx-hook=".Sha256">Hello World</div>
<script :type={Phoenix.LiveView.ColocatedHook} name=".Sha256">
import { sha256 } from "my-example-sha256-library";
import { reverse } from "@/vendor/vendored-file";
export default {
mounted() {
this.el.innerHTML = sha256(reverse(this.el.innerHTML));
}
};
</script>
"""
end
Guidelines:
node_modules@) to refer back into your assets folder instead of relative paths--alias=@=. by default so @/vendor/... maps into assetsIf your node_modules path is nonstandard, configure it via :node_modules_path in mix.exs:
# mix.exs
def project do
[
compilers: [:phoenix_live_view] ++ Mix.compilers(),
phoenix_live_view: [colocated_js: [node_modules_path: "assets/node_modules"]]
]
end
This is per-project and distinct from :target_directory.
Phoenix.LiveView.ColocatedJS supports several attributes on the <script> tag:
name – Name under which the default export is available from the manifest. If omitted, the script is imported for side effects only.key – Custom export key used in the manifest. Hooks use this to group exports under hooks (for example export { ... as hooks }). Must be a valid JS identifier and requires name to be set.extension – Custom extension for the extracted file. Defaults to js.manifest – Custom manifest filename instead of index.js (for example web_components.ts). Remember to update your import paths if you change this.Use this skill when you need to remember how colocated JS is compiled, named, and imported, or when deciding between colocated hooks and general colocated JS:
phx-hook, this.pushEventTo, this.handleEvent, etc.) – see the phoenix-colocated-hooks and phoenix-hooks skills.Phoenix.LiveView.ColocatedJS for JS that does not need hook semantics: web components, one-off helpers, or shared utilities colocated with templates.mix compile before your asset build (or include it in aliases) so the phoenix-colocated manifest is up to date.