【发布时间】:2016-07-14 05:18:31
【问题描述】:
我正在使用带有 CommonJs 的 browserify。
我有这个结构的文件 2。
module.exports = {
value: 'bling bling'
};
我有具有这种结构的文件 1。
var file2 = require('./file2.js');
console.log('this is the file 2 object value', file2.value);
所以我在终端中运行以下命令
$ browserify -g uglifyify ./file1.js | uglifyjs -c > bundle.js
捆绑的结果是。
!function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&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}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){var file2=require("./file2.js");console.log("this is the file 2 object value",file2.value)},{"./file2.js":2}],2:[function(require,module,exports){module.exports={value:"bling bling"}},{}]},{},[1]);
我想知道是否有机会通过任何转换为我的捆绑文件获得不同的结果,以获得以下结果。
var file2 = { value: 'bling bling' }; console.log('this is the file 2 object value', file2.value);
我只希望我的代码在最终结果中没有任何额外的 browserify 或 webpack 或 requirejs 编码,可能是我使用该工具不正确,但在使用每个工具时总是会发生这种情况。
其中一些工具产生或多或少的编码,但我不知道如何删除这些额外的代码。
【问题讨论】:
-
试试这个:github.com/rollup/rollup Browserify 或 webpack 总是会生成这个额外的代码。
标签: javascript requirejs compression webpack browserify