aurelia / webpack-plugin

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

webpack 5 plugin element injection in ie 11 #175

Closed elitastic closed 3 years ago

elitastic commented 3 years ago

I'm submitting a bug report

Current behavior: "Element" is not injected correctly in IE 11 when using @autoinject.

There's no problem at all in Chrome/Firefox (unfortunately we must still support IE 11).

There are two available workarounds to fix it in IE 11:

What is the expected behavior? Should work in IE 11 without enabling any workarounds

Repro webpack.config.js

const path = require('path');
const basedir = __dirname;
const { AureliaPlugin } = require('aurelia-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    target: 'web',
    mode: 'none',
    devtool: false,
    resolve: {
        extensions: ['.ts', '.js'],
        modules: ['src', 'node_modules']
    },
    entry: {
        'main': ['promise-polyfill/src/polyfill', 'aurelia-bootstrapper', path.resolve(basedir, 'src', 'main.ts')]
    },
    output: {
        filename: '[name]-[contenthash].js',
        path: path.resolve(basedir, 'dist'),
        environment: {
            arrowFunction: false,
            const: false,
            destructuring: false,
            module: false,
            bigIntLiteral: false,
            dynamicImport: false,
            forOf: false
        }
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                exclude: /node_modules/,
                use: [{
                    loader: 'ts-loader',
                    options: {
                        transpileOnly: true
                    }
                }]
            },
            {
                test: /\.html$/,
                use: [{
                    loader: 'html-loader',
                    options: {
                        minimize: true,
                        esModule: false
                    }
                }]
            }
        ]
    },
    plugins: [
        new AureliaPlugin(),
        new HtmlWebpackPlugin({
            template: 'src/index.tmpl',
            inject: true,
            filename: 'index.html'
        })
    ]
};

main.ts

import 'aurelia-polyfills';
import { Aurelia, PLATFORM } from 'aurelia-framework';

export async function configure(aurelia: Aurelia)
{
    aurelia.use
        .standardConfiguration()
        .developmentLogging('warn');

    await aurelia.start();
    await aurelia.setRoot(PLATFORM.moduleName('app'), document.body);
}

app.ts

import { autoinject } from 'aurelia-framework';

@autoinject()
export class App
{
    constructor(
        private element: Element)
    {
    }

    async activate()
    {
        alert(this.element?.tagName ? 'Element correctly injected' : 'There\'s a problem with element injection');
    }
}

app.html

<template>
   Hello World
</template>
bigopon commented 3 years ago

@elitastic I'll close this for now, since it should work with latest master already. Please feel free to open if your tests gets a different result.

elitastic commented 3 years ago

Unfortunately it's still not working with latest master. Still the same problem with @autoinject and native elements when transpileOnly is enabled in ts-loader.

elitastic commented 2 years ago

Could you please reopen this issue (see my previous answer)?

ItWorksOnMyMachine commented 2 years ago

I have never successfully gotten autoinject to work with interfaces because interfaces are compiled out by TS. In this case, I would simply use @inject(Element).