源文件中是否引用了Babel转换模块?

时间:2019-01-12 12:33:50

标签: javascript babel transpiler ecma

我希望Babel可以同时转换我的源代码和该源代码中引用的模块,但事实并非如此。

module.exports = {
    ignore: [/node_modules\/(?!@polymer|@webcomponents)/],
    exclude: /node_modules\/(?!(@webcomponents|@polymer)\/)/,
    test: /(src|node_modules\/@polymer)/,

    plugins: [
        ['@babel/plugin-transform-modules-commonjs', {
        allowTopLevelThis: true
        }]
    ],

    presets: [
        ['@babel/preset-env', {
        debug: true,
        targets: {
            node: 6
        }
        }]
    ]
};

与此相反:

import {PolymerElement, html} from '@polymer/polymer/polymer-element';
import 'fs';
console.log('hello, world', PolymerElement, html);

输出:

[temp 13:25:29] babel --copy-files --ignore ^\.\/node_modules --config-file ./babel.config.js  ./src -o ./dist/index.js; cat dist/index.js
@babel/preset-env: `DEBUG` option

Using targets:
{
"node": "6"
}

Using modules transform: auto

Using plugins:
    transform-function-name { "node":"6" }
    transform-for-of { "node":"6" }
    transform-dotall-regex { "node":"6" }
    transform-destructuring { "node":"6" }
    transform-exponentiation-operator { "node":"6" }
    transform-async-to-generator { "node":"6" }
    proposal-async-generator-functions { "node":"6" }
    proposal-object-rest-spread { "node":"6" }
    proposal-unicode-property-regex { "node":"6" }
    proposal-json-strings { "node":"6" }
    proposal-optional-catch-binding { "node":"6" }

Using polyfills: No polyfills were added, since the `useBuiltIns` option was not set.

"use strict";

var _polymerElement = require("@polymer/polymer/polymer-element");

require("fs");

console.log('hello, world', _polymerElement.PolymerElement, _polymerElement.html);

0 个答案:

没有答案