Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usage with Encore + webpack 4 + babel 7 + corejs #359

Open
Gamesh opened this issue Apr 5, 2019 · 3 comments
Open

usage with Encore + webpack 4 + babel 7 + corejs #359

Gamesh opened this issue Apr 5, 2019 · 3 comments

Comments

@Gamesh
Copy link

Gamesh commented Apr 5, 2019

Solution proposed in symfony/webpack-encore#97 (comment) no longer works.
It works as expected until i configure babel with runtime generator and corejs to support async/await and generators

import "core-js/stable";
import "regenerator-runtime/runtime";

as detailed here https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md

My Routing wrapper: Routing.js

const Routing = require('../../../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.js')
const routes = require('../../../../web/js/fos_js_routes.json')

Routing.setRoutingData(routes)
module.exports = Routing

webpack encore config:

.configureBabel(
    function(babelConfig) {
      babelConfig.plugins.push('@babel/plugin-proposal-object-rest-spread')
      babelConfig.plugins.push('@babel/plugin-syntax-import-meta')
      babelConfig.plugins.push('@babel/plugin-proposal-json-strings')
      babelConfig.plugins.push('@babel/plugin-proposal-class-properties')
      babelConfig.plugins.push('@babel/plugin-transform-react-jsx-source')
    },
    { useBuiltIns: 'usage', corejs: 3 },
  )

when i load the page i get an error
"root is undefined"
which refers to:
root.Routing = routing.Routing; router.js line 13

@julienbdx
Copy link

Same here.
Have you found any solution ?

@Gamesh
Copy link
Author

Gamesh commented Apr 28, 2019

nope, had to remove corejs and polyfill, then it started working again

@mfleonhardt
Copy link

Confirmed. I'm not using corejs, just polyfills. Removing the preset-env section removes the error.

Encode.configureBabel(function (babelConfig) {
        const preset = babelConfig.presets.find(([name]) => name === "@babel/preset-env");
        if (preset !== undefined) {
            preset[1].useBuiltIns = "usage";
        }

        babelConfig.plugins.push('@babel/plugin-proposal-class-properties');
    });

I can't not use polyfills, so I'm working around by slightly adapting the @weaverryan method (https://symfonycasts.com/screencast/javascript-webpack/fosjsroutingbundle):

{% block scripts %}
    <script src="{{ asset('/bundles/fosjsrouting/js/router.min.js') }}"></script>
{% endblock %}
// routing.js
const routes = require('./data/routes');
window.Routing.setRoutingData(routes);
module.exports = window.Routing;

// app.js
import Routing from './routing';
console.log(Routing.generate('my_route', {param: 1}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants