talyssonoc / react-laravel

Package for using ReactJS with Laravel
895 stars 90 forks source link

Doesn't work with webpack #52

Closed 18601673727 closed 8 years ago

18601673727 commented 8 years ago

Hi Talysson,
I'm trying to move Elixir's babel() to straight webpack, but v8js seems didn't recognize a component file like this:

/******/ (function(modules) { // webpackBootstrap
/******/    // The module cache
/******/    var installedModules = {};

/******/    // The require function
/******/    function __webpack_require__(moduleId) {

/******/        // Check if module is in cache
/******/        if(installedModules[moduleId])
/******/            return installedModules[moduleId].exports;

/******/        // Create a new module (and put it into the cache)
/******/        var module = installedModules[moduleId] = {
/******/            exports: {},
/******/            id: moduleId,
/******/            loaded: false
/******/        };

/******/        // Execute the module function
/******/        modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/        // Flag the module as loaded
/******/        module.loaded = true;

/******/        // Return the exports of the module
/******/        return module.exports;
/******/    }

/******/    // expose the modules object (__webpack_modules__)
/******/    __webpack_require__.m = modules;

/******/    // expose the module cache
/******/    __webpack_require__.c = installedModules;

/******/    // __webpack_public_path__
/******/    __webpack_require__.p = "/js/";

/******/    // Load entry module and return exports
/******/    return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

    "use strict";

    var Alert = React.createClass({
      displayName: "Alert",

      render: function render() {
        return React.createElement(
          "h1",
          { className: "text-center" },
          "Alert something there!"
        );
      }
    });

/***/ }
/******/ ]);

which gives me error like this:

V8Js::compileString():1: ReferenceError: Alert is not defined

but this works:


    var Alert = React.createClass({
      displayName: "Alert",

      render: function render() {
        return React.createElement(
          "h1",
          { className: "text-center" },
          "Alert something there!"
        );
      }
    });
18601673727 commented 8 years ago

I found some kinda of a workaround to resolve this

global.Alert = Alert; // Add this to the bottom of entry jsx file
talyssonoc commented 8 years ago

Yes, you have to make them global, since V8Js doesn't know about CommonJS! It's here: https://github.com/talyssonoc/react-laravel#usage