Skip to content

Split morphic.js into many files and use a task runner to combine them#47

Open
menasheh wants to merge 12 commits intojmoenig:masterfrom
menasheh:master
Open

Split morphic.js into many files and use a task runner to combine them#47
menasheh wants to merge 12 commits intojmoenig:masterfrom
menasheh:master

Conversation

@menasheh
Copy link

@menasheh menasheh commented Apr 15, 2018

Getting to know morphic was very difficult for me when everything was stuffed in one file.

I think this way is better:
src folder for source
docs folder for documentation
dist folder for generated files
examples folder for examples
run gulp scripts to update the generated files after changing the source files.

What do you think?

fixes #46
fixes #4

@menasheh
Copy link
Author

Also worth mentioning - sourcemaps point back to the original files in src from chrome's javascript console, for example.

image

@menasheh
Copy link
Author

menasheh commented Apr 15, 2018

Also, I wanted it structured this way so it could be an npm package... Really, snap should require that package and not have morphic's code duplicated there.

Unless morphic isn't useful without snap, in which case this is really just part of snap? Some of the files in snap source might not be useful except for snap or might not be useful except for with morphic, and it's a little confusing because they're all just hanging out in the repository's root directory...

@menasheh
Copy link
Author

menasheh commented Apr 16, 2018

I realized that src/morphic.js wasn't being used - that syntax for including stuff was probably based on some random other build tool or plugin I tried while investigating how to do what I wanted to do.* So now the files are just listed in order in the gulpfile.

@menasheh
Copy link
Author

menasheh commented Apr 16, 2018

*What did I want to do?

  • morphic.js source code separated into several files.
  • generate morphic.js by concatenating the files in the proper order.
  • generate morphic.min.js for use on live systems, to ease the network load.
  • sourcemap for morphic.js, so that errors in development can be easily traced back to the original source file
  • sourcemap for morphic.min.js, so that errors in production can be easily traced back to the original source file
  • deploy an npm package for packages which want to extend morphic.js. For example, snap could require that package instead of including morphic in source control duplictously.

Then, snap would build morphic by including the appropriate files from node_modules/morphic-gui in its own gulpfile...

Right now I have them all listed manually in the gulpfile. In order to get the same level of sourcemaps that morphic itself has in its examples, dependencies would have to copy that list into their own gulp.src() method. That's a little bit messy, but it does work...

What would be better if we could use a wildcard to include all the files in the src directory. However, so far I found no way to order them if we use src/**/*.js as the source directory unless I appended 000_ to each filename, incrementing with the appropriate index, to force it to get the ordering right. That could work, then dependencies would just add the same folder, but through the path in node_modules. If there's a way to take the list of files out of the gulpfile, which I'm sure there is, but I haven't found it and/or gotten it working yet.

@jmoenig
Copy link
Owner

jmoenig commented Apr 17, 2018

this is really nice, @menasheh. I'll love to have a closer look at your work when my current bout of travelling is over. Just wanted to let you know that I'm looking at your contributions and am enjoying them!

@menasheh
Copy link
Author

menasheh commented Jan 25, 2019

Do you have time to examine this approach now? (If you like it I can redo it to be up to date with current changes.)

Also relevant PR on the snap repo jmoenig/Snap#2083

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

Successfully merging this pull request may close these issues.

Would it be possible to split morphic.js into 65 files and use a bundler of some sort? suggestion: splitting morphic.js in multiple files

2 participants