example-react-router-server-rendering-lazy-routes icon indicating copy to clipboard operation
example-react-router-server-rendering-lazy-routes copied to clipboard

Consider using babel-plugin-remove-webpack

Open knpwrs opened this issue 10 years ago • 3 comments

I just published my first babel plugin, babel-plugin-remove-webpack. It automatically rewrites calls to require.ensure and require.include so the developer doesn't have to worry about them. A suggestion came up over at reddit that I talk with you guys about using it over here.

I'm open to your thoughts and suggestions.

knpwrs avatar Jan 08 '16 15:01 knpwrs

Same solution :- ) https://github.com/morlay/babel-plugin-transform-ensure-ignore

morlay avatar Jan 18 '16 07:01 morlay

Only both solutions don't work with how require.ensure is used in this repo's RootRoute.js:11

Regardless, I think maybe it's better to avoid hiding such tricky transformations but rather keep them in code to prevent errors in case babel will be replaced/deprecated in the future? Just a thought.

sergeylukin avatar Mar 27 '16 13:03 sergeylukin

Just ran babel --presets es2015 --plugins remove-webpack RootRoute.js and got the following:

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _App = require('../components/App');

var _App2 = _interopRequireDefault(_App);

var _Index = require('../components/Index');

var _Index2 = _interopRequireDefault(_Index);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// polyfill webpack require.ensure
if (typeof require.ensure !== 'function') require.ensure = function (d, c) {
  return c(require);
};

exports.default = {
  path: '/',
  component: _App2.default,
  getChildRoutes: function getChildRoutes(location, cb) {
    (function () {
      cb(null, [require('./AboutRoute')]);
    })();
  },

  indexRoute: {
    component: _Index2.default
  }
};

Am I missing something? Why wouldn't that work? The only thing I see about this repo off-hand is that it uses Babel 5.

knpwrs avatar Mar 28 '16 17:03 knpwrs