diff --git a/src/AureliaDependenciesPlugin.ts b/src/AureliaDependenciesPlugin.ts index a838fdd..930b6b0 100644 --- a/src/AureliaDependenciesPlugin.ts +++ b/src/AureliaDependenciesPlugin.ts @@ -46,10 +46,13 @@ class ParserPlugin { // This covers commonjs modules, for example: // const _aureliaPal = require("aurelia-pal"); // _aureliaPal.PLATFORM.moduleName("id"); + // Or (note: no renaming supported): + // const PLATFORM = require("aurelia-pal").PLATFORM; + // PLATFORM.moduleName("id"); parser.plugin("evaluate MemberExpression", (expr: Webpack.MemberExpression) => { if (expr.property.name === "moduleName" && - expr.object.type === "MemberExpression" && - expr.object.property.name === "PLATFORM") { + (expr.object.type === "MemberExpression" && expr.object.property.name === "PLATFORM" || + expr.object.type === "Identifier" && expr.object.name === "PLATFORM")) { return new BasicEvaluatedExpression().setIdentifier("PLATFORM.moduleName").setRange(expr.range); } return undefined; diff --git a/src/AureliaPlugin.ts b/src/AureliaPlugin.ts index 5fea129..1224822 100644 --- a/src/AureliaPlugin.ts +++ b/src/AureliaPlugin.ts @@ -20,6 +20,7 @@ export interface Options { dist: string; entry?: string | string[]; features: { + ie?: boolean; svg?: boolean; unparser?: boolean; polyfills?: Polyfills; @@ -63,6 +64,7 @@ export class AureliaPlugin { options); this.options.features = Object.assign({ + ie: true, svg: true, unparser: true, polyfills: <"es2015">"es2015", @@ -92,6 +94,7 @@ export class AureliaPlugin { const defines: any = { AURELIA_WEBPACK_2_0: "true" }; + if (!features.ie) defines.FEATURE_NO_IE = "true"; if (!features.svg) defines.FEATURE_NO_SVG = "true"; if (!features.unparser) defines.FEATURE_NO_UNPARSER = "true"; definePolyfills(defines, features.polyfills!); @@ -157,13 +160,15 @@ export class AureliaPlugin { if (!dllPlugin && !opts.noWebpackLoader) { // Setup aurelia-loader-webpack as the module loader // Note that code inside aurelia-loader-webpack performs PLATFORM.Loader = WebpackLoader; - this.addEntry(compiler.options, "aurelia-loader-webpack"); + // Since this runs very early, before any other Aurelia code, we need "aurelia-polyfills" + // for older platforms (e.g. `Map` is undefined in IE 10-). + this.addEntry(compiler.options, ["aurelia-polyfills", "aurelia-loader-webpack"]); } if (!opts.noHtmlLoader) { // Ensure that we trace HTML dependencies (always required because of 3rd party libs) let module = compiler.options.module; - let rules = module.rules || (module.rules = []); + let rules = module.rules || module.loaders || (module.rules = []); // Note that this loader will be in last place, which is important // because it will process the file first, before any other loader. rules.push({ test: /\.html?$/i, use: "aurelia-webpack-plugin/html-requires-loader" }); @@ -200,9 +205,9 @@ export class AureliaPlugin { ); } - addEntry(options: Webpack.Options, module: string) { + addEntry(options: Webpack.Options, modules: string|string[]) { let webpackEntry = options.entry; - let entries = [module]; + let entries = Array.isArray(modules) ? modules : [modules]; if (typeof webpackEntry == "object" && !Array.isArray(webpackEntry)) { // There are multiple entries defined in the config // Unless there was a particular configuration, we modify the first one diff --git a/src/SubFolderPlugin.ts b/src/SubFolderPlugin.ts index fdd87a5..3d3de16 100644 --- a/src/SubFolderPlugin.ts +++ b/src/SubFolderPlugin.ts @@ -13,7 +13,10 @@ export class SubFolderPlugin { // Only look for request not starting with a dot (module names) // and followed by a path (slash). Support @scoped/modules. let match = /^(?!\.)((?:@[^/]+\/)?[^/]+)(\/.*)$/i.exec(request.request); - if (!match || request.context[subFolderTrial]) { cb(); return; } + // Fix: it seems that under some error conditions `request.context` might end up being null. + // this is bad but to help users find relevant errors on the web, we don't want to crash + // so instead we just skip the request. + if (!match || !request.context || request.context[subFolderTrial]) { cb(); return; } let [, module, rest] = match; // Try resolve just the module name to locate its actual root let rootRequest = Object.assign({}, request, { request: module }); diff --git a/src/webpack.d.ts b/src/webpack.d.ts index e4554b1..f0bccb0 100644 --- a/src/webpack.d.ts +++ b/src/webpack.d.ts @@ -98,6 +98,7 @@ declare namespace Webpack { target: string; module: { rules?: { test?: RegExp; use: string | string[] }[]; + loaders?: { test?: RegExp; use: string | string[] }[]; // same as rules, supported for backward compat with 1.x }; resolve: { alias: { [key: string]: string };