jonbretman / amd-to-as6

Converts AMD modules into ES6 modules
165 stars 37 forks source link

Give an option to replace the AMD path #22

Closed piuccio closed 6 years ago

piuccio commented 8 years ago

Requirejs allows to import absolute names and define a mapping in configuration like below

requirejs.config({
    //By default load any module IDs from js/lib
    baseUrl: 'js/lib',
    //except, if the module ID starts with "app",
    //load it from the js/app directory. paths
    //config is relative to the baseUrl, and
    //never includes a ".js" extension since
    //the paths config could be for a directory.
    paths: {
        app: '../app'
    }
});

I'm not saying this module should support the requirejs configuration, but it would be handy if at least it exposed a method to modify the imported path. For instance

const convert = require('amd-to-es6');

convert(`
   define(['app'], function (app) {});
`, {
   renameDependencyPath: function (path) {
      // path === 'app'
      return './modified/path/' + path;
   }
});

would generate

import app from './modified/path/app';