Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comments in the imported file via "require" should be removed. #21

Open
osv opened this issue Jun 27, 2021 · 4 comments
Open

Comments in the imported file via "require" should be removed. #21

osv opened this issue Jun 27, 2021 · 4 comments

Comments

@osv
Copy link

osv commented Jun 27, 2021

Currently If you use "require" to import npm's lib (like in lib/ramda - $lib_ramda = require('ramda/src/index.js') as typeof import('ramda')) than comments will be not removed.

Example of generated web.js source
// ...
var $node = $node || {}
void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "ramda/src/" ) ] }; 
;
/**
 * A function that always returns `false`. Any passed in parameters are ignored.
 *
 * @func
 * @memberOf R
 * @since v0.9.0
 * @category Function
 * @sig * -> Boolean
 * @param {*}
 * @return {Boolean}
 * @see R.T
 * @example
 *
 *      R.F(); //=> false
 */
var F = function () {
  return false;
};

module.exports = F;
;

$node[ "ramda/src/F" ] = $node[ "ramda/src/F.js" ] = module.exports }.call( {} , {} )
;

var $node = $node || {}
void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "ramda/src/" ) ] }; 
;
/**
 * A function that always returns `true`. Any passed in parameters are ignored.
 *
 * @func
 * @memberOf R
 * @since v0.9.0
 * @category Function
 * @sig * -> Boolean
 * @param {*}
 * @return {Boolean}
 * @see R.F
 * @example
 *
 *      R.T(); //=> true
 */
var T = function () {
  return true;
};

module.exports = T;
;

$node[ "ramda/src/T" ] = $node[ "ramda/src/T.js" ] = module.exports }.call( {} , {} )
;

// ... and so on
@nin-jin
Copy link
Member

nin-jin commented Jun 28, 2021

You can require minified version: dist/ramda.min.js

@osv
Copy link
Author

osv commented Jun 28, 2021

You can require minified version: dist/ramda.min.js

suddenly no! :) I don't know why, but ramda.min.js does not works, I tried to beatify ramda.min.js code and find reason, but failed. Error when I'm doing const {invertObj} = $lib_ramda:

Cannot destructure property 'invertObj' of '$.$lib_ramda' as it is undefined.

Similar problem might be actual for other modules used by "require"

Also another point why comments need to be removed, I can prepare some lib for myself with items that I will need:, e.g

    export let $my_ramda = {
        invertObj: require( 'ramda/src/invertObj.js' ) as typeof import( 'ramda' ).invertObj,
        uniq: require( 'ramda/src/uniq.js' ) as typeof import( 'ramda' ).uniq,
        concat: require( 'ramda/src/concat.js' ) as typeof import( 'ramda' ).concat,
        mergeWith: require( 'ramda/src/mergeWith.js' ) as typeof import( 'ramda' ).mergeWith,
        keys: require( 'ramda/src/keys.js' ) as typeof import( 'ramda' ).keys
	}

and builder removes comments from mol's sources, but not from required files, there are no sense in vendor's lib's comments.

@nin-jin
Copy link
Member

nin-jin commented Jun 28, 2021

Comments from TS sources are removed by typescript. In the future we should use some bundler to import NPM modules. Current implementation is very limited.

@osv
Copy link
Author

osv commented Jun 28, 2021

agree, maybe no need to focus on it too much now.
Yes, we can collect all import ... and require and bundle them separately with tree shaking, etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants