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

a module will be bundled twice? #7

Closed
lessfish opened this issue Jun 20, 2018 · 3 comments
Closed

a module will be bundled twice? #7

lessfish opened this issue Jun 20, 2018 · 3 comments

Comments

@lessfish
Copy link

lessfish commented Jun 20, 2018

I make another file named message2.js, and the content is as below:

import {name} from './name.js';

export default `hello2 ${name}!`;

and the run the script, the variable queue is as below:

[ { id: 0,
    filename: './../example/entry.js',
    dependencies: [ './message.js', './message2.js' ],
    code: '"use strict";\n\nvar _message = require("./message.js");\n\nvar _message2 = _interopRequireDefault(_message);\n\nvar _message3 = require("./message2.js");\n\nvar _message4 = _interopRequireDefault(_message3);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nconsole.log(_message2.default);\nconsole.log(_message4.default);',
    mapping: { './message.js': 1, './message2.js': 2 } },
  { id: 1,
    filename: '../example/message.js',
    dependencies: [ './name.js' ],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\n\nvar _name = require("./name.js");\n\nexports.default = "hello " + _name.name + "!";',
    mapping: { './name.js': 3 } },
  { id: 2,
    filename: '../example/message2.js',
    dependencies: [ './name.js' ],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\n\nvar _name = require("./name.js");\n\nexports.default = "hello2 " + _name.name + "!";',
    mapping: { './name.js': 4 } },
  { id: 3,
    filename: '../example/name.js',
    dependencies: [],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\nvar name = exports.name = \'world\';',
    mapping: {} },
  { id: 4,
    filename: '../example/name.js',
    dependencies: [],
    code: '"use strict";\n\nObject.defineProperty(exports, "__esModule", {\n  value: true\n});\nvar name = exports.name = \'world\';',
    mapping: {} } ]

so the name.js will be bundled twice?

or it's not considered in the minipack?

thanks

@Williammer
Copy link

Williammer commented Jun 21, 2018

It is skipped in the minipack.

To avoid parsing same module twice, you can simply add checking in the for .. of queue loop of createGraph function.

@ronami
Copy link
Owner

ronami commented Jun 21, 2018

Hey @hanzichi, thanks for your interest :)

Yes, in this case, the name.js module will be bundled (and parsed) twice.

I chose not to cover this case and other cases (like caching module exports and circular dependencies) to keep minipack's implementation as simple as possible.

@lessfish
Copy link
Author

@Williammer @ronami

so the case is not considered in the minipack as I thought, thanks for your explanations

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

3 participants