Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Webpack Dev Middleware Should Support export default #1378

Closed
@RehanSaeed

Description

@RehanSaeed

I have extended one of your templates and added the following NPM scripts so that I can write my Webpack configuration using TypeScript which has a number of advantages:

"build:webpackconfig": "tsc --lib es6 webpack.config.vendor.ts && tsc --lib es6 webpack.config.ts",
"build": "npm run build:webpackconfig && webpack --config webpack.config.vendor.js && webpack",
"build:prod": "npm run build:webpackconfig && webpack --config webpack.config.vendor.js --env.prod && webpack --env.prod"

This totally works and Webpack is happy with my JavaScript file generated from TypeScript however the WebpackDevMiddleware fails to run with the error:

One or more errors occurred. (TypeError: Cannot read property 'publicPath' of undefined

My TypeScript looks like this:

import * as path from "path";
import * as webpack from "webpack";
import { IArguments, INewConfiguration, INewConfigurationBuilder } from "./webpack.common";

const configurationBuilder: INewConfigurationBuilder = 
  (env: IArguments): INewConfiguration => {
    const configuration: INewConfiguration = {
      // ...
    };
    return configuration;
  };
export default configurationBuilder;

This outputs the following JavaScript:

"use strict";
exports.__esModule = true;
var path = require("path");
var webpack = require("webpack");

var configurationBuilder = function (env) {
  var configuration = {
    // ...
  };
  return configuration;
};
exports["default"] = configurationBuilder;

The key difference is the last line of code. I've experimented with changing it and the WebpackDevMiddleware only works when it is module.exports = configurationBuilder;. To generate that line in TypeScript I have to use export = configurationBuilder; which is invalid TypeScript because the default tsconfig.json file has module set to es2015.

The key point is that Webpack supports exports["default"] = configurationBuilder;, so the WebpackDevMiddleware should too.

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