-
Fototrend
JavaScript != Java (A JavaScript nem összekeverendő a Javával, két különböző programozási nyelvről van szó!)
Új hozzászólás Aktív témák
-
Jim-Y
veterán
Gondoltam megmutatom, hogy hogy működik a browserify, mert viszonylag egyszerűen be lehet mutatni:
Vannak a forrás fájlok:
.
├── app.js
├── index.html
├── module1.js
├── module2.js
└── node_modules
└── browserifymodule1
======='use strict';
module.exports.hello = function(world) {
return 'hello, ' + world();
};module2
======='use strict';
module.exports.world = function() {
return 'world!';
};app
==='use strict';
var module1 = require('./module1.js'),
module2 = require('./module2.js');
document.querySelector('body > div > p').innerText = module1.hello(module2.world);Majd itt használjuk fel a browserify-t egy bundle készítésre, terminálban a gyökér könyvtárban ki kell adni ezt a parancsot:
browserify app.js > bundle.js
index.html
========<!DOCTYPE html>
<head>
<title>Browserify</title>
</head>
<body>
<div>
<p></p>
</div>
<script src="bundle.js"></script>
</body>
</html>Tehát a html-be már csak a bundle-t húzzuk be, illetve a webszerverre/CDN-re is már csak a bundle-t kell feltenni.
A bundle pedig ezt tartalmazza:
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var module1 = require('./module1.js'),
module2 = require('./module2.js');
document.querySelector('body > div > p').innerText = module1.hello(module2.world);
},{"./module1.js":2,"./module2.js":3}],2:[function(require,module,exports){
'use strict';
module.exports.hello = function(world) {
return 'hello, ' + world();
};
},{}],3:[function(require,module,exports){
'use strict';
module.exports.world = function() {
return 'world!';
};
},{}]},{},[1]);Sok-sok olvashatatlan dolog, de látszik, hogy végső soron a te fájlaidat rakja össze.
Üdv -
Új hozzászólás Aktív témák
- Apple iPhone 16 Pro Max - Desert Titanium - 256GB 1 ciklus 100% akku! 1 év garancia! Új készülék!
- Telefon felvásárlás!! iPhone 16/iPhone 16 Plus/iPhone 16 Pro/iPhone 16 Pro Max
- Update 07.03. Bomba árak 2025-ben is! Üzleti - Consumer laptopok DELL FUJITSU HP LENOVO
- Zebra ZP505 EPL - Hőpapíros címkenyomtató
- Tablet felvásárlás!! Samsung Galaxy Tab A8, Samsung Galaxy Tab A9, Samsung Galaxy Tab S6 Lite
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: Promenade Publishing House Kft.
Város: Budapest