1 Star 0 Fork 0

diogoxiang / remote-component-starter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Remote Component Starter Kit

Starter Kit

Starter Kit for quickly creating a Remote React Component that can be Remotely Loaded by @paciolan/remote-component.

Getting Started

Clone the repository and initialize your project

# create new repo
mkdir my-component
cd my-component
git init

# pull the remote component starter kit
git pull https://github.com/Paciolan/remote-component-starter.git --depth=1
git commit --amend -m "chore: 🛠️ pull remote-component-starter"

# install dependencies
npm ci

Modify package.json and replace the starter kit values with your own.

  • set name to the name of your project.
  • set description to describe your project.
  • set repository to point to your repository.
  • set license to reflect the license of your project.

Files

There are a few important files, one set is used for the bundle, another set for local development.

  • src/index.js - Entrypoint of the Remote Component. The component needs to be the default export.
  • src/webpack-dev-server.js - Entrypoint for webpack-dev-server. This is only used for development and will not be included in the final bundle.
  • src/index.html - HTML for webpack-dev-server. This is only used for development and will not be included in the final bundle.

Building

The bundle will be output to the dist/main.js.

npm run build

Create a development build for easier debugging.

npm run build:dev

Debugging

The component can be debugged locally by first starting webpack-dev-server.

npm run start

Now (using VSCODE), go to the Debug tab, select "Launch Chrome" and start the debugger (F5).

You should now be able to set breakpoints and step through the code.

Changing the Output

The bundle as a default will be output to the dist/main.js. This can be updated by changing the following two files:

  1. entry in webpack-main.config.js. Update the main property to a desired output name.
module.exports = {
  ...
  entry: {
    main: "./src/index.js"
  },
  ...
};
  1. url variable in src/webpac-dev-server.js
// different paths for localhost vs s3
const url =
  global.location.hostname === "localhost" ? "/dist/main.js" : "main.js";

External Dependencies

The Remote Component is self contained with all of it's dependencies bundled with webpack. Any dependencies that will be provided by the app should be marked as external in the webpack.config.js.

In this example, react and prop-types are added to externals. They will not be included in the bundle. The web application is expected to provide these dependencies.

module.exports = {
  output: {
    libraryTarget: "commonjs"
  },
  externals: {
    react: "react",
    "prop-types": "prop-types"
  }
};

Commiting

Commits are added to the repository with commitizen compatible git-cz.

# stage all changes
git add .

# run commitizen
npm run cz

Contributors

Joel Thoms (https://twitter.com/joelnet)

Icon made by Freepik from www.flaticon.com

The MIT License (MIT) Copyright (c) 2019 Paciolan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Starter Kit for quickly creating a Remote React Component that can be Lazily Loaded by @paciolan/remote-component 展开 收起
NodeJS 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
NodeJS
1
https://gitee.com/diogoxiang/remote-component-starter.git
git@gitee.com:diogoxiang/remote-component-starter.git
diogoxiang
remote-component-starter
remote-component-starter
master

搜索帮助