Transform two es6 modules into one file with babel

711 views Asked by At

I have files a.js and main.js:

a.js:

export default A = 7;

main.js:

import A from './a'
console.log(A);

I want somehow process that files to get one result file (let say result.js), which I can add into html page (via <script src="result.js"></script>), so that when I load this html page in browser, I see 7 in console. There should be no require() or import ... from ... directives in result.js.


I try compile file main.js with babel:

babel main.js --presets env --out-file result.js

But this gives me file result.js with require() directive and without code from a.js:

'use strict';
var _a = require('./a');
var _a2 = _interopRequireDefault(_a);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.log(_a2.default);

Also I try to compile both files a.js and main.js with babel:

babel a.js main.js --presets env --out-file result.js

This gives me file result.js with code from a.js but also with require() directive:

"use strict";
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = A = 7;
'use strict';
var _a = require('./a');
var _a2 = _interopRequireDefault(_a);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.log(_a2.default);

How can I process that files correctly to get result.js without require() or import ... from ... directives?

0

There are 0 answers