babeljs

Convert ES6 to ES2015 using babel and laravel-mix

*爱你&永不变心* 提交于 2019-12-18 16:56:13
问题 I have ES6 JavaScript code in my Vue components. In order to support IE 11 I need to convert it to ES5 code using babel and laravel-mix. How do I do that? Here is my webpack.mix.js file. let mix = require('laravel-mix'); mix.js('resources/assets/js/app.js', 'public/js') .js('resources/assets/js/admin-app.js', 'public/js') 回答1: There's a mix.babel() command that can handle this. It's identical to mix.scripts() so it requires a little more legwork. I cheat and do this and then serve the es5.js

babel 7 - how to prevent adding of “strict mode” [duplicate]

断了今生、忘了曾经 提交于 2019-12-18 16:55:20
问题 This question already has answers here : How to stop babel from transpiling 'this' to 'undefined' (and inserting “use strict”) (2 answers) Closed 7 months ago . I looked at many posts but still cannot get this to work :( I have .babelrc { "comments": false, "presets": [ ["@babel/env", { "targets": { "browsers": ["ios 7"] } }], ["minify"] ] } I want to tell babel to not add "use strict" (anywhere) How is this done ? 回答1: Babel assumes by default that files being transformed are ES modules.

babel 7 - how to prevent adding of “strict mode” [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-18 16:55:11
问题 This question already has answers here : How to stop babel from transpiling 'this' to 'undefined' (and inserting “use strict”) (2 answers) Closed 7 months ago . I looked at many posts but still cannot get this to work :( I have .babelrc { "comments": false, "presets": [ ["@babel/env", { "targets": { "browsers": ["ios 7"] } }], ["minify"] ] } I want to tell babel to not add "use strict" (anywhere) How is this done ? 回答1: Babel assumes by default that files being transformed are ES modules.

Jest Test Babel Error: Plugin/Preset files are not allowed to export objects

孤人 提交于 2019-12-18 14:55:54
问题 I'm using a very up-to-date (December 2017) stack of dependencies. As I try-out isomorphic react tests with Jest, the test suit keeps failing with the following error: * Test suite failed to run [BABEL] /__tests__/router.test.js: Plugin/Preset files are not allowed to export objects, only functions. Here are my dependencies: "dependencies": { "axios": "^0.17.1", "babel-polyfill": "^6.26.0", "cors": "^2.8.4", "express": "^4.16.2", "react": "^16.1.1", "react-dom": "^16.1.1", "react-router-dom":

How convert .jsx to .js with Gulp and Babel?

筅森魡賤 提交于 2019-12-18 14:16:12
问题 I need to convert all /src/ .jsx files to /src/ .js Before I used gulp-react: var react = require('gulp-react'); gulp.task('jsx', function () { return gulp.src('src/jsx/*.jsx') .pipe(react()) .pipe(gulp.dest('src/js/')); }); It works but not without some small mistakes. When I use Babel website (https://babeljs.io/repl/) all converts right. Could you help me. How can I set gulp to convert .JSX files? 回答1: First you need to install these two packages: npm install gulp-babel babel-plugin

Source Maps not working with Webpack

混江龙づ霸主 提交于 2019-12-18 13:59:51
问题 I'm pretty new to webpack and having some trouble configuring it to produce the necessary source maps. In the devtools it says Source Map detected but it shows the bundle and not the original code: Here is my webpack.config.js: module.exports = { entry: [ 'webpack-dev-server/client?http://localhost:8080/', 'webpack/hot/dev-server', "./src/index.js" ], output: { filename: 'bundle.js', path: '/', }, debug: true, devtool: 'source-map', resolve: { extensions: ['', '.jsx', '.scss', '.js', '.json']

How do I get Webpack to transpile ES6 code?

偶尔善良 提交于 2019-12-18 13:38:00
问题 I'm pretty new to Webpack, and I'm just trying to get a simple project off the ground here. I'm getting the following error: ERROR in ./index.js Module parse failed: /Users/jay/Documents/personal_projects/open_phil_grants_visualizer/index.js Unexpected token (6:16) You may need an appropriate loader to handle this file type. | import App from './app'; | | ReactDOM.render(<App />, document.getElementById('content')); | @ multi (webpack)-dev-server/client?http://localhost:8080 ./index.js Here

Javascript Proxy support in Babel

一世执手 提交于 2019-12-18 12:15:46
问题 I'm using babelify version 6.3.0 set to stage 0. ES6 / ES7 are working great. However when I try to use Javascript's proxy functionality: set product(product={}) { this._product = new Proxy({}, {}) } I get: ReferenceError: Can't find variable: Proxy Any ideas? 回答1: From the Babel website: Due to the limitations of ES5, Proxies cannot be transpiled or polyfilled. See support in various JavaScript engines. 回答2: You cannot proxy a full object with all the traps but you can create proxied

Make webpack's library output compatible with babel6

淺唱寂寞╮ 提交于 2019-12-18 11:35:41
问题 Babel's 6th version changes the functioning of export default and in particular its relation with commonjs require . To summarise, while until babel5, require('module') where giving the default export of the module, it now always returns the module object containing all of the exports of the module. If one only wants the default, he/she must use require('module').default . As explained here, there is very good reasons behind this and the aim of this question is not to break or hack this

Requires Babel “7.0.0-0” but was loaded with “6.26.3”

痴心易碎 提交于 2019-12-18 11:17:20
问题 Keep getting this error no matter what I tried installing (babel wise) as I follow other similar reports. this is the stack trace: error: bundling failed: Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure you have a compatible version of @babel/core, it is likely that something in your build process is loading the wrong version. Inspect the stack trace of this error to look for the first entry that doesn't mention "@babel/core" or "babel-core" to see what is