# Extract Custom Web Component after build

**URL:** <https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237>\
**Category:** Help Requests\
**Created:** [February 14, 2020, 12:01am UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237 "2020-02-14T00:01:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![harwee](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/harwee/32/1739_2.png) [@harwee](https://discourse.aurelia.io/u/harwee)\
**Post date:** [February 14, 2020, 12:01am UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237/1 "2020-02-14T00:01:18Z")

</div>

I am trying to create Web Components from Aurelia components using [aurelia-web-components](https://github.com/aurelia/web-components)

This is my main.ts file

```
import {PLATFORM} from 'aurelia-pal';
import { CustomElementRegistry } from 'aurelia-web-components';

export function configure(aurelia) {
  aurelia.use
    .standardConfiguration()
    .developmentLogging()
    .globalResources(PLATFORM.moduleName('resources/elements/my-element'));

  aurelia
    .start()
    .then(() => {
      const registry = aurelia.container.get(CustomElementRegistry);

      //The following line takes all global resource custom elements and registers them as web components.
      //Once the element is registered, in-page elements will begin rendering.
      registry.useGlobalElements();
    });
}

```

The Readme states that after running au build (npm run build)

> You will find the compiled code in the `dist` folder, available in module formats: UMD, AMD, CommonJS and ES6.

but all the files are either chunk or bundle scripts along with `index.html` Is there any configuration I am missing so that it can generate each custom element in a different file?

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [February 14, 2020, 1:04am UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237/2 "2020-02-14T01:04:44Z")

</div>

The sentence you referred to means that the build output of the plugin (aurelia-web-component plugin) will be at dist folder, not your code. For your web component code, you can distribute them independently. Does it help make anything clearer?

---

<div class="post-metadata">

**Author:** ![harwee](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/harwee/32/1739_2.png) [@harwee](https://discourse.aurelia.io/u/harwee)\
**Post date:** [February 14, 2020, 1:20am UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237/3 "2020-02-14T01:20:00Z")

</div>

> The sentence you referred to means that the build output of the plugin

Oh ok that part was confusing, so the plugin just converts custom element to work more like web component in existing app.

> For your web component code, you can distribute them independently

Can you tell me how to do this? like I have an element `my-element` with both template and script files, how can i generate `my-element.js` which i can use in other Aurelia projects or frameworks?

> Does it help make anything clearer?

Thanks it does clear a lot of confusion!!

Edit: Fixed styling

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [February 14, 2020, 2:05am UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237/4 "2020-02-14T02:05:12Z")

</div>

You don’t need to do anything special, only need to export your element like normal, and the consumer of your code can register that themselves.

Or you can enforce consumption of your plugin via plugin API only, via exporting a single `configure` function like following example:

```auto
import { FrameworkConfiguration } from 'aurelia-framework';
import { MyElement } from './my-element';
import { CustomElementRegistry } from 'aurelia-web-components';

export function configure(config: FrameworkConfiguration) {
  // need to register with `postTask` to ensures all core modules have been initialized
  config.postTask(() => {
    config.get(CustomElementRegistry).register(MyElement);
  });
}

```

Then in other app, consume your plugin:

```auto
import { configure as configureMyElementWebComponent } from 'my-element-module';

...
aurelia.use.plugin(configureMyElementWebComponent);

// or
aurelia.use.plugin(PLATFORM.moduleName('my-element-module'));

```

---

<div class="post-metadata">

**Author:** ![harwee](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/harwee/32/1739_2.png) [@harwee](https://discourse.aurelia.io/u/harwee)\
**Post date:** [February 14, 2020, 2:40am UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237/5 "2020-02-14T02:40:14Z")

</div>

This forces us to ship Aurelia code where ever we want to use this component, more like [vue-web-component-wrapper](https://github.com/vuejs/vue-web-component-wrapper)

So as long as we play in Aurelia ecosystem there is need to ship extra code other than the component itself.

Thanks for the clarification!!

---

<div class="post-metadata">

**Author:** ![djedi](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/djedi/32/312_2.png) [@djedi](https://discourse.aurelia.io/u/djedi)\
**Post date:** [November 9, 2021, 10:14pm UTC](https://discourse.aurelia.io/t/extract-custom-web-component-after-build/3237/6 "2021-11-09T22:14:19Z")

</div>

Does anyone have an example of an Aurelia web component being used in another framework like React or Ember?
