Skip to content

Loading WebComponents, consisting of multiple files #75

Open

Description

@christianscharr

When using @angular/cli to create WebComponents one ends up with at least 2 files for each WebComponent: main.js and styles.js.
But the elementConfig only supports a single URL per element. Sure, I can concatenate the files builded into a single file, this works for production, but not when I want to debug the app locally via ng serve :(

Activity

  1. maxfriedmann commented on Feb 10, 2021

    @maxfriedmann

    We also have that problem and never found a better solution than writing a cli for that use case: https://www.npmjs.com/package/@smallstack/ng-wc-serve

    If you want to try it out, then please keep in mind that you need to package your webcomponent as production.

    If you ever find a better solution, please let us know :)

  2. fcioffi commented on Mar 6, 2021

    @fcioffi

    Hi,
    when I build for production I merge all files (with nodejs custom script) so the problem is only in dev environment.
    In dev you can create an initializer in order to load other files when module load.

    my 2 cents.
    Francesco

  3. gs-smuthyam commented on Mar 16, 2021

    @gs-smuthyam

    Hi @christianscharr

    we are using ngx-build-plus and exporting as a single file, you might wanna try this out.

  4. arturovt commented on Jun 17, 2021

    @arturovt
    Collaborator

    Hey @christianscharr . You'd need to use the @angular-builders/custom-webpack to extend the inbuilt configuration. There're 3 Webpack entries, which are main, polyfills and styles. You only need to merge main and styles entries:

    // extra-webpack.config.js
    module.exports = (config) => {
      if (Array.isArray(config.entry.styles)) {
        config.entry.main = [...config.entry.main, ...config.entry.styles];
      }
    
      return config;
    };

    This will bundle styles and main into a common file at the end. This is what ngx-build-plus is doing already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions