aurelia / webpack-plugin

A plugin for webpack that enables bundling Aurelia applications.
MIT License
90 stars 36 forks source link

fix(pal): ie 11 selection #188

Closed bigopon closed 3 years ago

bigopon commented 3 years ago

At the moment, determining pal module is not enough for v5, where target of the webpack configuration could take the type string | false | string[] | undefined. Currently, this is casted to string, as it's rarely needed more than that. However, for IE11, with the recommendation from webpack being target: ['web', 'es5'], the following code becomes insufficient:

function getPAL(target: string) {
  switch (target) {
    case "web": return "aurelia-pal-browser";
    case "webworker": return "aurelia-pal-worker";
    case "electron-renderer": return "aurelia-pal-browser";
    default: return "aurelia-pal-nodejs";
  }
}

Change it to:

function getPAL(target?: string | string[] | false) {
  if (target instanceof Array) {
    if (target.includes('web') || target.includes('es5')) {
      return 'aurelia-pal-browser';
    }

    // not really sure what to pick from an array
    target = target[0];
  }
  if (target === false) {
    throw new Error('Invalid target to build for AureliaPlugin.');
  }
  switch (target) {
    case undefined:
    case "es5":
    case "web":
      return "aurelia-pal-browser";
    case "webworker": return "aurelia-pal-worker";
    case "electron-renderer": return "aurelia-pal-browser";
    default: return "aurelia-pal-nodejs";
  }
}

This should also help prevent issues with aurelia-pal-nodejs not found when target is not specified. Nodejs app shouldn't be the default.

Tested on IE for the test app at tests/app-simple image

Closes #187

Thanks @ItWorksOnMyMachine and @elitastic

@elitastic for #175 , can you check again a few things, against latest master after this is merged:

Additionally, added a basic tests with aurelia-testing to verify that the build actually works.

elitastic commented 3 years ago

https://github.com/aurelia/webpack-plugin/issues/175#issuecomment-886468962