如果我在JS文件中使用 ES6 import ,如:
import { tempates } from "./templates.js";
webpack converts 这类似于:
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var _templates_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./templates.js */ "./static/js/templates.js");
这是否意味着 I can use ES6 modules 和 due to the transformation of webpack 他们将 also work in old browsers 不支持ES6模块?
如果是的话: difference between 这个 transformation webpack 是什么,那个 babel 怎么办?例如,描述了巴贝尔的变换 . 这里:https://babeljs.io/docs/plugins/transform-es2015-modules-commonjs/
在旧版浏览器中 advantages/disadvantages using babel or webpack 与 ES6 module compatibilty 有什么关系?
我正在使用webpack版本4.10.2,这是我的webpack配置:
var path = require('path');
module.exports = {
mode: 'development',
entry: './static/js/mainScript.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'asterics-grid.bundle.js'
}
};
1 回答
这是Webpack的目的之一 .
Webpack是一个捆绑包 . 巴贝尔是一个转录者 . 他们应该一起使用 . Babel
transform-es2015-modules-commonjs
转换将ES模块转换为CommonJS模块 . Node.js支持CommonJS模块,但浏览器不支持 .优点是您可以在旧版浏览器中使用ES模块 . 缺点是Webpack可能会引入诸如如何处理循环依赖性之类的限制 .