H
H
Hazrat Hajikerimov2018-02-26 11:12:28
JavaScript
Hazrat Hajikerimov, 2018-02-26 11:12:28

What is the correct way to export a compressed (uglifyjs) npm package?

Greetings, I wrote a simple wrapper over api using ES7 features, then I transpiled the whole thing with the help of webpack, or rather even with the help of babel, transpiled it into ES5.
The problem is that when I import it in another project, I get just an empty object,
although it is in the package code. export default
In this regard, I have a number of questions that I would like to receive answers from the community

  1. Why do I get import library from 'library'an empty object if there isexport default
  2. Can UglifyJS create such problems? Or is uglify only needed for packages that need to be included directly in the browser and it doesn't make sense to compress regular packages? If so, what if someone decides to connect my package to himself and he does not have the necessary plugin for babel, for example property-class-transform, the assembly will not work for him
  3. How to properly create an npm project that can be used both on the client and on the server? I mean, it export'ы's module.exportsnot in the browser, how can I access my package in the browser, because it is isolated from the global scope? use window.myLibrary? is this the normal approach?
  4. Maybe it's in package.json, I have the path to the compressed file in the main property

Package itself: https://github.com/hazratgs/kurtuba-storage-client

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Hazrat Hajikerimov, 2018-03-04
@hazratgs

Found a solution in the webpack documentation, the section is called Authoring Libraries

M
Mikhail Osher, 2018-02-26
@miraage

https://github.com/reactjs/redux
Take a close look at rollup.config.js and package.json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question