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

Converting ES to JS #10

Open
jesse1983 opened this issue Apr 4, 2017 · 4 comments
Open

Converting ES to JS #10

jesse1983 opened this issue Apr 4, 2017 · 4 comments

Comments

@jesse1983
Copy link

Hi guys. Actually I'm converting all react projects to MarkoJS (congratulations, it's amazing).

I found a little problem: browser compatibilities. On react projects, my webpack use babel-preset-es2015/babel-preset-react for convert:

query: {
   presets: ['es2015', 'react'],
},

How to do the same approach in MarkoJS?

@larixer
Copy link
Contributor

larixer commented Apr 6, 2017

Hi @jesse1983

The discussion here might be helpful
marko-js/marko#430

So if you turn on babel to transpile .marko files after marko-loader and transpile .js files, you will have ES6 transpilling support with Marko for the browser.

And if your JS-code for some component is inside component.js, you will still have to use module.exports instead of ES6 export, e.g.

class ComponentClass {
  onInput(input) {
    // ...
  }
}

module.exports = ComponentClass;

@jasonmacdonald
Copy link

jasonmacdonald commented Apr 10, 2017

You can use the "add-module-exports" Babel plugin to handle converting "export default" to "modules.exports" for you. That way even your components can be ES6.

@jesse1983
Copy link
Author

Take a look my resolution for this issue:

1 - First, I have install Babel Webpack Plugin (https://www.npmjs.com/package/babel-webpack-plugin)

2 - Then, just I added it on webpack.config.js as a PLUGIN e not a LOADER:

/* my webpack.config.js */
plugins: [
   new BabelPlugin({test: /\.js$/, presets: ['es2015']]}
]

I believe that is a approach to solve this case.

@cameronbraid
Copy link
Contributor

@jesse1983 that solution works, but is very slow.

Using babel loader means only individual .js files that change get transpiled. Using BabelPlugin means the whole output asset(s) gets transpiled

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

No branches or pull requests

4 participants