[英]Nodejs - No webpack bundle
I want to "bundle" some files into a single js file, but I don't want the webpack wrapper. 我想将一些文件“捆绑”成一个js文件,但是我不想使用webpack包装器。
Let's say I have 3 files : 假设我有3个文件:
// file1.js
export default { hello: "hello" };
// file2.js
export default { world: "world" };
// index.js
import file1 from "./file1";
import file2 from "./file2";
(() => ({ ...file1, ...file2 }))()
I want the following result : 我想要以下结果:
// build/output.js (+ babel...)
(function(){
return Object.assign({}, { hello: "hello" }, { world: "world" });
})()
Not a single line of code apart from the above build output. 除了上述构建输出外,没有一行代码。
Is it possible with webpack? webpack可以吗? Thanks!
谢谢!
Ok, so I found a solution! 好的,所以我找到了解决方案! It's maybe not the best one, but it works.
它可能不是最好的,但它可以工作。
I found this library here which concatenates files together. 我在这里找到了将文件连接在一起的库 。
I can build using : npm run build
. 我可以使用以下命令
npm run build
: npm run build
。
And the code that concatenates the files is : 连接文件的代码是:
// ======================================================
// Tools / Bundle
// ======================================================
// Libs
var path = require("path");
var bundle = require("bundle-js");
module.exports.exec = function() {
// Disable logging (hack for 'bundle-js' library).
var _log = console.log;
console.log = function() {};
// Concatenate each file (required by the application).
var file = path.resolve(__dirname, "../src/index.js");
var bundledCode = bundle({
entry: file,
print: false,
disablebeautify: true
});
// Enable logging.
console.log = _log;
// Return bundled code.
return bundledCode;
};
For some reasons, bundle-js always outputs something even with the option { print: false }
. 由于某些原因,即使使用选项
{ print: false }
, bundle-js也会始终输出某些内容。 So I added a small hack to fix this. 因此,我添加了一个小技巧来解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.