How to debug the source of a modal plugin written in ES6?

regardless of the build step, you are always going to be importing a script in the head of an HTML document, this script is the one that the browser is running, and this is the source of truth, debugging this script is no different than debugging any other script.

When developers started to bundle and minify their js files, it became really hard to debug these js files, this is why browsers shipped a feature called source maps, source maps enable you to debug a script as if it was standalone even though it could have been minifed, combined, and transpiled along the way.

Whether or not sourcemaps are included for a certain script will depend on the setup/build. Usually you want these in development, but you don't want them in production.

for example, here is webpack configuration for the sourcemaps https://webpack.js.org/configuration/devtool/#devtool


Edit to expand upon the previous answer

I'm going to explain in details here how to debug the glide package, using source-maps, and also how to develop using local packages because it seems from the comments that you also want to know this. of-course here glide is just an example since you wanted to know for this package specifically, but this approach can be used for any other package.

Developing using local packages will enable you to debug code without having to go to index.js file in the dist folder in your node modules.

Using source maps will enable you to see the files as they are originally, line to line.

  • Fork the glide package and clone it to your pc, and install dependencies
  • Here you can use any example that uses glide, but i set up an example, Fork/clone the following repo https://github.com/sanehab/parcel-glide, and install dependencies
  • Now Let's say you want to do some changes in the glide package, and you want to test them before publishing/ or doing a pull request, without developing against the local version this can be a really time consuming.
  • Now in order to use the local package there are a lot of ways, for now we are using the simplest way which is to install a package using the absolute path (I'm assuming here that you use a new npm version that is compatible with installing packages using absolute paths). Go to the package.json file in the parcel-glide and change
"@glidejs/glide": "sanehab/glide"

To

"@glidejs/glide": "absolute path for glide package on your system"

Then run npm/yarn install

Now run npm star (in parcel-glide package), you will see the example running, any changes now you do for the glide package should be seen here directly (after you do npm run build in glide package or use watch if you want)

Add a console statement to index.js in glide package to make sure everything is working (and then build using npm run build). - now if you go to the example, and you see the sources, you will find that we have one huge glide js file, and that we have no access in the sources folder for all the files in glide package, for example the ones that are in src/components. In order to have this access we need to add source-maps

Now in glide package go to build/build.js and change

import banner from './banner'
import babel from 'rollup-plugin-babel'

export default {
  output: {
    name: 'Glide',
    banner
  },
  plugins: [
    babel({
      plugins: [
        'external-helpers',
        'transform-object-assign'
      ]
    })
  ]
}

To 

import banner from './banner'
import babel from 'rollup-plugin-babel'

export default {
  output: {
    name: 'Glide',
    banner,
    sourcemap: "inline"
  },
  plugins: [
    babel({
      plugins: [
        'external-helpers',
        'transform-object-assign'
      ]
    })
  ]
}

Run npm run build and now you can access all the files in the sources panel in dev tools, including the individual files of glide package.

There are different types of source maps, inline are the most accurate however they are slowest, different options affect the build/rebuild speed, You want to choose what suits you the best.

Again this is a sum up of what i have also written in my first edit, from the browser point of view it always see js files, if you want to see how a minified, combined, trans-piled, or what so ever a file was before it is processed you need to enable source maps, how you enable them will depend upon the used tool for doing the processing (the build step). It is often easy and you just have to add a property specifying what source maps you want or if you want at all.


Just as you would with any other piece of github hosted code you want to contribute to:

  1. Clone the repository at https://github.com/ghosh/micromodal
  2. Examine package.json or the documentation for building instructions.

Go ahead and investigate and contribute!

It's even described in detail in the readme:

Development setup

  • Clone Github repo $ git clone https://github.com/ghosh/micromodal.git
  • Install yarn package manager (Read installation guide)
  • Run yarn install in the root folder to install all dependencies
  • Run yarn dev to start a dev server. This serves the example directory and live reloads when any files are changed
  • [Optional] Run yarn build to build the files for distribution. This is run automatically as a pre-commit hook as well.
  • Send us pull request and chill

https://github.com/ghosh/micromodal#development-setup