GithubHelp home page GithubHelp logo

ronami / minipack Goto Github PK

View Code? Open in Web Editor NEW
3.1K 40.0 314.0 26 KB

📦 A simplified example of a modern module bundler written in JavaScript

License: MIT License

JavaScript 100.00%
javascript parcel-bundler webpack example browserify modules commonjs es6-modules module-bundler es2015

minipack's People

Contributors

chinanf-boy avatar hg-pyun avatar ranyitz avatar rkrupinski avatar ronami avatar roymiloh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

minipack's Issues

a module will be bundled twice?

I make another file named message2.js, and the content is as below:

import {name} from './name.js';

export default `hello2 ${name}!`;

and the run the script, the variable queue is as below:

[ { id: 0,
    filename: './../example/entry.js',
    dependencies: [ './message.js', './message2.js' ],
    code: '"use strict";\n\nvar _message = require("./message.js");\n\nvar _message2 = _interopRequireDefault(_message);\n\nvar _message3 = require("./message2.js");\n\nvar _message4 = _interopRequireDefault(_message3);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nconsole.log(_message2.default);\nconsole.log(_message4.default);',
    mapping: { './message.js': 1, './message2.js': 2 } },
  { id: 1,
    filename: '../example/message.js',
    dependencies: [ './name.js' ],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\n\nvar _name = require("./name.js");\n\nexports.default = "hello " + _name.name + "!";',
    mapping: { './name.js': 3 } },
  { id: 2,
    filename: '../example/message2.js',
    dependencies: [ './name.js' ],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\n\nvar _name = require("./name.js");\n\nexports.default = "hello2 " + _name.name + "!";',
    mapping: { './name.js': 4 } },
  { id: 3,
    filename: '../example/name.js',
    dependencies: [],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\nvar name = exports.name = \'world\';',
    mapping: {} },
  { id: 4,
    filename: '../example/name.js',
    dependencies: [],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\nvar name = exports.name = \'world\';',
    mapping: {} } ]

so the name.js will be bundled twice?

or it's not considered in the minipack?

thanks

possibility of adding more introductory code regarding file loaders?

Hi! 😄 thank you for creating this project! It's a great way to understand bundlers more.

File loaders are also a heavily used feature provided by different bundlers. Would you accept very introductory code regarding loaders? Basically we could create a different example folder showing how minipack would work with file loaders.

Here's a gist with a very basic css file loader example (along with the generated bundle.js):
https://gist.github.com/mayank23/6163214ce6b7562bd300b9a79ef5dde4. (still needs explanation comments)

If interested I could make a PR for this. I feel that having some introductory examples of heavily used bundler features would immensely help also.

Thank you!!

Question on code comment: 'This loop will terminate when the queue is empty.'

Thanks so much for this simple example!
It really revealed the 'magic' behind javascript bundler for me.

There is a point I'm not quite understand though.

Regarding the for .. of loop in the createGraph function

minipack/src/minipack.js

Lines 115 to 117 in ce3b1b5

// only has one asset but as we iterate it we will push additional new assets
// into the queue. This loop will terminate when the queue is empty.
for (const asset of queue) {

To my understanding, the loop will terminate when

  1. there are no more child asset being pushed to the end of query
  2. the code reached the end of query

which also means the the dependency graph was completed.
Hence the query will never be empty (there is at least one asset: the entry/main asset)
Or did I misunderstand something here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.