Skip to content

Instantly share code, notes, and snippets.

@ipoddubny
Last active February 11, 2024 22:33
Show Gist options
  • Save ipoddubny/1f5718a8d927fdcd9884 to your computer and use it in GitHub Desktop.
Save ipoddubny/1f5718a8d927fdcd9884 to your computer and use it in GitHub Desktop.
webpack amd and cjs mixture
define(['cjs'], function (cjs) {
console.log('amd module loaded');
console.log('cjs exported:', cjs);
return 'AMD';
});
define([], function () {
console.log('This module has been loaded asynchronously');
return 'ASYNC';
});
console.log('cjs module loaded');
module.exports = 'CJS';
var amd = require('amd');
console.log('this is main.js');
console.log('amd module exported:', amd);
setTimeout(function () {
require(['async'], function (async) {
console.log('async module returned:', async);
});
}, 5000);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Webpack demo</title>
</head>
<body>
<h1>Webpack demo</h1>
<script src="bundle.js"></script>
</body>
</html>
module.exports = {
entry: 'main.js',
output: {
filename: 'bundle.js'
},
resolve: {
root: [
__dirname
],
extensions: ['', '.js']
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment