ronami / minipack Goto Github PK
View Code? Open in Web Editor NEW📦 A simplified example of a modern module bundler written in JavaScript
License: MIT License
📦 A simplified example of a modern module bundler written in JavaScript
License: MIT License
Sometimes you just want a TL;DR version, code only. Too many comments might make it hard to read the code...
I want to know ,the data structure that is bundle function returned, and the bootstrap function.what does above ideas inspire from?
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
const graph = createGraph('./example/entry.js');
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!!
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
Lines 115 to 117 in ce3b1b5
To my understanding, the loop will terminate when
child
asset being pushed to the end of query
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.