【发布时间】:2020-06-21 05:03:38
【问题描述】:
我有 2 个文件,a.js 和 b.js:
a.js:
function hello() {
alert('hey');
alert('bye');
}
b.js:
const name = 'Bob';
alert(name)
我将它们都导入到我的入口文件中:
import './a';
import './b';
我想把它们结合起来,我的 webpack.config.js 是这样的:
const path = require('path');
module.exports = {
entry: './entry.js',
mode: 'production',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
}
};
当我运行 webpack 时,我得到一个模块:
// etc...
/***/ (function(module, exports) {
function hello() {
alert('hey');
alert('bye');
}
/***/ }),
/* 2 */
/***/ (function(module, exports) {
const name = 'Bob';
alert(name)
/***/ })
/******/ ]);
相反,我怎样才能得到:
function hello() {
alert('hey');
alert('bye');
}
const name = 'Bob';
alert(name)
This plugin 完成了我想要实现的目标,但是有一个错误,我无法缩小组合文件,除此之外,我还想运行 babel 将代码转换为与 es5 兼容。所有这些事情似乎比常规的 webpack 方式要容易得多,所以如果我能让 webpack 导出一个普通的脚本而不是一个模块,那就太好了..
【问题讨论】:
-
不清楚你想要什么,但是这个呢:stackoverflow.com/a/40416826/2581562
标签: javascript webpack