I want to trade disk space for no named function calling in webpack so that I can do language analysis easier.
However webpack' ing the following modules,
import foo.js; foo()
import foo.js; foo()
import bar.js; console.log(bar()) console.log(bar()) console.log(bar())
import bar.js; console.log(bar()) console.log(bar()) console.log(bar())
return "THIS IS BAR!"
Results in:
function bar() { return "THIS IS BAR!"; }
function foo() {
console.log(bar());
console.log(bar());
console.log(bar());
}
foo();
And I want,
function foo() {
console.log((() => { return "THIS IS BAR!" })());
console.log((() => { return "THIS IS BAR!" })());
console.log((() => { return "THIS IS BAR!" })());
}
foo();
Even while this will increase the space of the bundle. Because I want to avoid function calling.
So far I have tried with several { optimization: { ... } }
rules but none of them leads to the desired result.
Did you try with the mode production. With current setting. I can see desire output.
// foo.js
import bar from './bar'
export default function print() {
console.log(bar())
console.log(bar())
console.log(bar())
}
// bar.js
export default function bar() {
return "THIS IS TEST"
}
// webpack.config.js
const path = require('path');
module.exports = {
mode: "production",
entry: './src/foo.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'foo.bundle.js'
}
};
// Version
"webpack": "^4.42.0", "webpack-cli": "^3.3.11"
// Output
([function(e,t,n){"use strict";function r(){console.log("THIS IS TEST"),console.log("THIS IS TEST"),console.log("THIS IS TEST")}n.r(t),n.d(t,"default",(function(){return r}))}]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.