laravel-mix-react-typescript-extension icon indicating copy to clipboard operation
laravel-mix-react-typescript-extension copied to clipboard

laravel mix 6 support?

Open torian257x opened this issue 5 years ago • 2 comments

when using laravel mix 6 beta 14

I get:

$ yarn watch
yarn run v1.19.1
$ mix watch
[webpack-cli] ReferenceError: File is not defined
    at /home/myuser/myproject/src_dev/react/node_modules/laravel-mix-react-typescript-extension/index.js:19:42
    at Array.map (<anonymous>)

any ideas?

torian257x avatar Nov 20 '20 03:11 torian257x

solution seems to be to use laravel-mix file: only 2nd line is new, everything else same


let mix = require("laravel-mix");
let File = require('../laravel-mix/src/File');

class ReactTypeScript {
  constructor() {
    this.toCompile = [];
  }

  dependencies() {
    return [
      "@babel/preset-typescript",
      "@babel/preset-react",
      "@babel/plugin-proposal-class-properties",
      "@babel/plugin-proposal-object-rest-spread",
      "typescript"
    ];
  }

  register(entry, output) {
    entry = [].concat(entry).map(file => new File(file));
    output = new File(output);

    this.toCompile.push({ entry, output });
  }

  webpackEntry(entry) {
    this.toCompile.forEach(js => {
      entry.addFromOutput(
        js.entry.map(file => file.path()),
        js.output,
        js.entry[0]
      );
    });
  }

  webpackRules() {
    return [
      {
        test: /(\.js)|(\.jsx)|(\.ts)|(\.tsx)$/,
        exclude: /(node_modules)/,
        use: [
          {
            loader: "babel-loader",
            options: Config.babel()
          }
        ]
      }
    ];
  }

  webpackConfig(webpackConfig) {
    webpackConfig.resolve.extensions.push(".ts", ".tsx");
  }

  babelConfig() {
    return {
      presets: ["@babel/preset-typescript", "@babel/preset-react"],
      plugins: [
        "@babel/proposal-class-properties",
        "@babel/proposal-object-rest-spread"
      ]
    };
  }
}

mix.extend("reactTypeScript", new ReactTypeScript());


torian257x avatar Nov 20 '20 04:11 torian257x

Any updates on this? this package is also 8 months old and hasnt been updated

theoparis avatar Jan 21 '21 03:01 theoparis