{"id":18441626,"url":"https://github.com/stefanwalther/es6-debug-webstorm","last_synced_at":"2025-04-07T22:32:28.146Z","repository":{"id":149090094,"uuid":"46818798","full_name":"stefanwalther/es6-debug-webstorm","owner":"stefanwalther","description":"How to debug ES6 in Webstorm (using gulp)","archived":false,"fork":false,"pushed_at":"2017-10-17T20:44:35.000Z","size":185,"stargazers_count":61,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T17:54:31.441Z","etag":null,"topics":["debugging","es2015","es6","javascript","webstorm"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stefanwalther.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-24T21:10:26.000Z","updated_at":"2022-04-03T09:51:29.000Z","dependencies_parsed_at":"2023-06-30T04:46:10.630Z","dependency_job_id":null,"html_url":"https://github.com/stefanwalther/es6-debug-webstorm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanwalther%2Fes6-debug-webstorm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanwalther%2Fes6-debug-webstorm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanwalther%2Fes6-debug-webstorm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stefanwalther%2Fes6-debug-webstorm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stefanwalther","download_url":"https://codeload.github.com/stefanwalther/es6-debug-webstorm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247741543,"owners_count":20988427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugging","es2015","es6","javascript","webstorm"],"created_at":"2024-11-06T06:38:53.191Z","updated_at":"2025-04-07T22:32:28.140Z","avatar_url":"https://github.com/stefanwalther.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Debugging ES6 in WebStorm\n\n\u003e Just a short reminder for myself how to get debugging to work in WebStorm with ES6.\n\u003e If it helps also you, then great! ;-)\n\n**Folder structure** being used:\n\n```text\nroot\n|-- src\n   |-- index.js\n   |-- sample.js\n.babelrc\ngulpfile.babel.js\npackage.json\n\n```\n\nContent of `.babelrc`:\n```js\n{\n \"presets\": [\"es2015\"]\n}\n```\n\nThe setup described below uses gulp 3.x to transpile ES6 files to ES5, including source-maps, which can then be used in WebStorm to debug ES6.\n\n**Note:** \nAs soon as gulp 4.0 is out, some changes are necessary, gulp 4.0 introduces some breaking changes.\n\n## Prerequisites\nInstall the required modules as devDependencies:\n\n- babel-core\n- babel-preset-es2015\n- gulp\n- gulp-babel\n- gulp-sourcemaps\n\n\n```bash\n$ npm install babel-core babel-preset-es2015 gulp gulp-babel gulp-sourcemaps --save-dev\n```\n**Note:** `babel-core` and `gulp` can and probably should be installed globally.\n\n## Setup gulp to work with ES6\n\n- Instead of naming your gulp file `gulpfile.js` rename it to `gulpfile.babel.js`\n- Use the following gulp-script:\n\n```js\nimport gulp from \"gulp\";\nimport sourceMaps from \"gulp-sourcemaps\";\nimport babel from \"gulp-babel\";\nimport path from \"path\";\n\nconst paths = {\n\tes6: ['./src/**/*.js'],\n\tes5: './dist',\n\t// Must be absolute or relative to source map\n\tsourceRoot: path.join(__dirname, 'src')\n};\ngulp.task('babel', () =\u003e {\n\treturn gulp.src(paths.es6)\n\t\t\t.pipe(sourceMaps.init())\n\t\t\t.pipe(babel({\n\t\t\t\tpresets: ['es2015']\n\t\t\t}))\n\t\t\t.pipe(sourceMaps.write('.', { sourceRoot: paths.sourceRoot }))\n\t\t\t.pipe(gulp.dest(paths.es5));\n});\ngulp.task('watch', ['babel'], () =\u003e {\n\tgulp.watch(paths.es6, ['babel']);\n});\n\ngulp.task('default', ['watch']);\n```\n\nRunning `gulp` will now create a folder dist with the transpiled scripts + sourcemaps in it.\n\nInspirations for this script:\n- [2ality - Using transpiled ES6 on Node.js](http://www.2ality.com/2015/04/node-es6-transpiled.html)\n- [Using ES6 with gulp](https://markgoodyear.com/2015/06/using-es6-with-gulp/)\n\n\n## Setup your project\nJust as a simple example let's add the following files into `./src`:\n\n**sample.js**\n\n```js\nexport class Sample  {\n\tconstructor() {\n\t\tthis.prop1 = \"prop1\";\n\t\tthis.prop2 = \"prop2\";\n\t}\n}\n````\n\n**index.js**\n```js\nimport {Sample} from './sample';\nlet sample = new Sample();\nconsole.log( sample.prop1 );\nconsole.log( sample.prop2 );\n```\n\nNow run\n\n\tgulp\n\nWhenever you make changes, four file will be generated in the `./dist` folder:\n\n![](docs/images/generated_files.png)\n\n\n## Debug in WebStorm\nSo, now let's have a look how to debug in WebStorm (version 11 is used here):\n\nSet a breakpoint:\n- Go to the ./dist folder and create the desired breakpoint:\n\n![](docs/images/breakpoint.png)\n\nStart the debugger in WebStorm, by right-clicking on `dist/index.js` (not `src/index.js` !!!).\n\nYou will then get:\n\n![](docs/images/step1.png)\n\nSo, not really nice, probably a WebStorm bug.\nBut if you hit F8 (Step Over ![](docs/images/step-over-icon.png)) you will then get\n\n![](docs/images/step2.png)\n\nWe are done, happy debugging in WebStorm!\nYou can now set breakpoints in every of the files in the `./src/` folder (containing in this example the es6 files) and they will be hit.\n\n## Mocha setup\n\nConfigure the \n\n![](docs/images/mocha-webstorm-settings.png)\n\nMost important setting is the \"Extra Mocha options\" with `--compilers js:babel-core/register`\n\n# Further readings\n\n- https://github.com/lmarkus/es6-webstorm\n- https://github.com/rauschma/node-es6-demo\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanwalther%2Fes6-debug-webstorm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstefanwalther%2Fes6-debug-webstorm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstefanwalther%2Fes6-debug-webstorm/lists"}