定制 pnodev/livereload 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pnodev/livereload

Composer 安装命令:

composer require pnodev/livereload

包简介

Live Reload capabilities for TYPO3 development

README 文档

README

Latest Stable Version TYPO3 12 License

Live Reload for TYPO3

This extension adds Livereload capabilities to your TYPO3 instance.

Installation

Install the extension via composer

composer req --dev pnodev/livereload

Note We are using Composer NPM bridge to automatically install the Node dependencies that are needed to run the livereload server. At first run, it might ask you for permission to do that. Additionally, an npm postinstall script is executed to build the server.

Include the TypoScript configuration

The extension provides a TS constant that points to a JavaScript file that has to be inserted into the frontend in order for livereload to work. It is highly recommended to only include this in development mode and to deactivate the cache while using it.

Constants.typoscript

@import 'EXT:livereload/Configuration/TypoScript/constants.typoscript'

Setup.typoscript

[applicationContext == "Development"]
   page.includeJS.livereload = {$tx_livereload.fe_bundle}
   config.no_cache = 1
[end]

Create your configuration

Add a config section to the package.json of your site package (if you are using Node to process your CSS and JavaScript, you most likely already have a package.json). By default, livereload will look for a package.json in the current working directory. But you can point it to a different place by passing a --config flag to the command:

node ./vendor/pnodev/livereload/live-reload.mjs --config ./path/to/package.json

This is where you configure rules for reloading. A valid entry consists of the path or glob to be watched (relative to you site package) and a configuration object. For each path, you at least have to specify a type. Currently, there are the following types available:

typedescription
reloadImmediately reloads the entire page
streamA stream event does not reload the page. Instead it only injects the differences into the current document (much like HMR).
You can define a files array to only refresh specific files (like a linked JS or CSS file). If you do not specify files, the entire new document will be compared to the current one and only the parts that changed will be replaced.

package.json

{
    "name": "@pnodev/site-package",
    "config": {
        "livereload": {
            "host": "127.0.0.1",
            "port": "1337",
            "resources": {
                "js": {
                    "path": "./Resources/Public/Dist/main.min.js",
                    "type": "reload"
                },
                "templates": {
                    "path": "./Resources/Private/{Layouts,Partials,Templates,ContentElements}/**/*.html",
                    "type": "stream"
                },
                "css": {
                    "path": "./Resources/Public/Dist/main.min.css",
                    "type": "stream",
                    "files": [
                        "main.min.css"
                    ]
                }
            }
        }
    }
}

Usage

Livereload can be integrated in two ways:

  1. You trigger a reload / stream by watching a file (specified in your config).
  2. You trigger a reload by sending a request to the livereload server

The second option can be especially useful if you need for other processes to finish before looking for changes. Providing a convenient abstraction for this can be as easy as adding an npm script:

"scripts": {
  "reload": "curl -s http://localhost:1337/reload"
}

Additionally, you'll want to include the watch process that starts the livereload server in your build setup. Here is an example on how to do this:

{
   "name": "site_package",
   "scripts": {
      "watch": "node ../../vendor/pnodev/livereload/live-reload.mjs ../../../packages/site_package/livereload.config.mjs",
      "build:js": "esbuild ./Resources/Public/JavaScript/Src/main.js --outfile=./Resources/Public/JavaScript/main.js --bundle --minify --sourcemap",
      "build:css": "postcss ./Resources/Public/Css/tailwind.src.css -o ./Resources/Public/Css/main.css",
      "build": "yarn build:js && yarn build:css",
      "dev:css": "chokidar \"./Resources/Private/{Layouts,Partials,Templates}/**/*.html\" \"./tailwind.config.js\" -c \"yarn build\"",
      "dev:js": "yarn build:js --watch",
      "dev": "conc \"yarn build\" \"yarn dev:css\" \"yarn dev:js\" \"yarn watch\"",
      "reload": "curl -s http://localhost:1337/reload",
      "test": "echo \"Error: no test specified\" && exit 1"
   },
   "devDependencies": {
      "autoprefixer": "^10.4.13",
      "chokidar-cli": "^3.0.0",
      "concurrently": "^7.6.0",
      "cssnano": "^5.1.14",
      "esbuild": "^0.15.15",
      "postcss": "^8.4.19",
      "postcss-cli": "^10.0.0",
      "tailwindcss": "^3.2.4"
   }
}
  • The watch task starts the server and feed it the configuration file in your site package.
  • The dev task uses conc to start the processes for building CSS and JavaScript, as well as the watch task in parallel.

pnodev/livereload 适用场景与选型建议

pnodev/livereload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 194 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extension」 「typo3」 「livereload」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 pnodev/livereload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 pnodev/livereload 我们能提供哪些服务?
定制开发 / 二次开发

基于 pnodev/livereload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 194
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2023-01-17