英文:
Triggering live-reloading when developing an Ember addon
问题
我正在为我的团队开发一个私有的Ember插件,其中包含一些我们将在多个不同应用程序中重用的品牌UI组件,例如<BrandHeader />
和<BrandFooter />
。
是否有一种标准的方法来创建开发环境,允许您在构建组件时获得实时重新加载的预览?如果没有标准方法,是否有人有为您有效的工作流程?
我尝试过使用使用ember-cli创建插件ember addon <name>
,然后通过npm link
将其链接到Ember应用程序,其中我调用了这些组件,但是使用这种方法,我需要在每次对插件进行更改时重新构建Ember应用程序。
英文:
I'm developing a private Ember addon for my team that will contain a few branded UI components that we will reuse in a bunch of different apps, such as a <BrandHeader />
and <BrandFooter />
.
Is there an standard for creating a development environment that allows you to get live-reloading previews of your components as you build them? If there's not a standard, does anyone have a workflow that you've created that works well for you?
I tried using the strategy of creating an addon with the ember-cli ember addon <name>
and then npm link
ing to an Ember app where I call the components, but with that method I need to rebuild the ember app every time I make a change in to the addon.
答案1
得分: 1
在Ember文档中,我找不到明确解释这一点的地方,但我找到了答案:
ember addon <name>
命令会自动在tests/dummy
目录中创建一个"虚拟"应用程序。 您可以在此应用程序中使用您的插件组件,无需特殊配置。在下面的示例中,我只是添加了一行,您可以看到<BrandHeader>
组件被调用。
// tests/dummy/templates/application.hbs
{{page-title "Dummy"}}
<BrandHeader>Header text</BrandHeader>
<h2 id="title">Welcome to Ember</h2>
{{outlet}}
在项目的根文件夹中运行ember serve
会启动一个开发服务器,就像在普通的Ember应用程序中一样,它会为虚拟应用程序提供服务。对组件的更改将实时更新。
英文:
I couldn't find a place in the Ember documentation where this is clearly explained, but I found the answer:
The ember addon <name>
command automatically creates a "dummy" app in the tests/dummy
directory. You can use your addon components in this app with no special configuration. In the example below, I've just added the line where you see the <BrandHeader>
component being called.
// tests/dummy/templates/application.hbs
{{page-title "Dummy"}}
<BrandHeader>Header text</BrandHeader>
<h2 id="title">Welcome to Ember</h2>
{{outlet}}
Running ember serve
in the root folder of your project will start a development server like in a normal Ember app, serving the dummy app. Changes to components will live-update.
答案2
得分: 0
在确保在npm/yarn/pnpm项目之间进行链接时,使live-reload正常工作,有一些事情你需要注意:
在v1插件的<project-root>/index.js
中,你需要临时设置isDevelopingAddon
,如下所示:
module.exports = {
name: require('./package').name,
isDevelopingAddon: () => true,
}
如果你已安装Watchman,你可能可以跳过此步骤。
接下来,在你链接的应用程序中,你可能需要在ember-cli-build.js
中设置autoImport.watchDependencies
,如下所示:
// 在你的ember-cli-build.js文件中
let app = new EmberApp(defaults, {
autoImport: {
watchDependencies: [
// 如果“some-lib”在开发过程中更改,则触发重建
'some-lib',
// 如果“some-lib”的内部依赖“other-lib”更改,则触发重建
['some-lib', 'other-lib'],
// 如果在开发过程中任何依赖项更改,则触发重建
...Object.keys(require('./package').dependencies || {}),
],
},
});
在embroider下,我认为所有这些监视操作都会自动发生。
英文:
There are a couple things you'll want to look at to make sure that live-reload works between npm/yarn/pnpm link between projects:
In the v1 addon's <project-root>/index.js
, you'll want to temporarily set isDevelopingAddon
module.exports = {
name: require('./package').name,
isDevelopingAddon: () => true,
}
if you have Watchman installed, you may be able to skip this step.
Next, in your app that you linked to, you may need to set autoImport.watchDependencies
in your ember-cli-build.js
, like this:
// In your ember-cli-build.js file
let app = new EmberApp(defaults, {
autoImport: {
watchDependencies: [
// trigger rebuilds if "some-lib" changes during development
'some-lib',
// trigger rebuilds if "some-lib"'s inner dependency "other-lib" changes
['some-lib', 'other-lib'],
// trigger rebuilds if any of your dependencies change during development
...Object.keys(require('./package').dependencies || {}),
],
},
});
Under embroider, I believe all this watching happens automatically.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论