tree-shaking | Build this project

 by   thelgevold JavaScript Version: Current License: No License

kandi X-RAY | tree-shaking Summary

kandi X-RAY | tree-shaking Summary

tree-shaking is a JavaScript library. tree-shaking has no vulnerabilities and it has low support. However tree-shaking has 9 bugs. You can download it from GitHub.

Build this project by running.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              tree-shaking has a low active ecosystem.
              It has 8 star(s) with 0 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              tree-shaking has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of tree-shaking is current.

            kandi-Quality Quality

              tree-shaking has 9 bugs (0 blocker, 0 critical, 9 major, 0 minor) and 0 code smells.

            kandi-Security Security

              tree-shaking has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              tree-shaking code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              tree-shaking does not have a standard license declared.
              Check the repository for any license declaration and review the terms closely.
              OutlinedDot
              Without a license, all rights are reserved, and you cannot use the library in your applications.

            kandi-Reuse Reuse

              tree-shaking releases are not available. You will need to build from source code and install.
              It has 35 lines of code, 0 functions and 22 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of tree-shaking
            Get all kandi verified functions for this library.

            tree-shaking Key Features

            No Key Features are available at this moment for tree-shaking.

            tree-shaking Examples and Code Snippets

            No Code Snippets are available at this moment for tree-shaking.

            Community Discussions

            QUESTION

            Webpack5 does not seem to tree-shake unused exports
            Asked 2022-Mar-31 at 15:43

            I set up a small project with the following files

            ...

            ANSWER

            Answered 2022-Mar-31 at 15:43

            I figured it out myself, auto-answer for the record :

            The tsconfig.json was wrong, it wasn't preserving the ES6 module syntaxe so webpack couldn't treeshake properly.

            More details on the correct configuration (optionally including Babel too) can be found here

            Source https://stackoverflow.com/questions/71679366

            QUESTION

            Parcel 2 + Vue 3 - How to set global feature flags ? Vue Devtools disabled
            Asked 2022-Feb-04 at 14:39

            Starting a new project with Vue.js v3 and Parcel.js v2. Everything went fine for setting up and launching a humble Hello World app except this warning in the browser's console:

            ...

            ANSWER

            Answered 2021-Nov-23 at 17:43

            It looks like these warnings are generated when there are no global variables named __VUE_OPTIONS_API__ and __VUE_PROD_DEVTOOLS__ (see code).

            In a webpack setup, you can inject global variables at build time with the Define Plugin. Unfortunately, I'm not aware of any parcel2 plugin (yet) that does this (although it would be pretty simple to write). However, you could just create them yourself by writing this near the beginning of your app's entry .js file:

            Source https://stackoverflow.com/questions/70083869

            QUESTION

            How to configure vue.config.js to remove vue-i18n console error when using nm run serve
            Asked 2022-Jan-26 at 17:39

            I am very new to Vue and I am trying to set up vue-i18n and continue to get console warnings

            ...

            ANSWER

            Answered 2022-Jan-26 at 14:09

            The meaning of this warning message is that you need to specify the flag explicitly in the bundler when you do a production build.

            Please refer to the following link for packages provided by vue-i18n for bundlers.

            https://vue-i18n.intlify.dev/installation.html#with-a-bundler

            One advice to help you out is to use the plugins for each bundler listed in the NOTE section of the above link, and they will configure them properly for you. I recommend that you check them out.

            Checkout this issue listed in GitHub forum.

            Source https://stackoverflow.com/questions/70845703

            QUESTION

            Why is StoreDevtoolsModule in my production bundle, and how to remove it from there?
            Asked 2022-Jan-21 at 12:23

            Using webpack-bundle-analyzer I detected the module StoreDevtoolsModule into my production bundle.

            I though three shaking would removed it, but it does not...

            Is there a way to build in production mode without it? (it is not used anyway in production):

            ...

            ANSWER

            Answered 2022-Jan-21 at 12:23

            After discussing the problem with my peers, we figured that the reason for it to be in the bundle is that because environment.production is evaluated at runtime, tree shaking will not remove the module from the bundle. Event though it is not really used.

            There is a way around it though.

            first create 2 files:

            one to host the import array for non-prod (default), with the following contents

            src/hat-trick/store-dev-tools-import.ts

            Source https://stackoverflow.com/questions/70793430

            QUESTION

            Factoring out part of app into its own NPM package results in larger overall app size
            Asked 2021-Nov-14 at 16:35

            We are using create-react-app and Typescript within all of our projects and a slightly large module of commonly used React components has emerged. Trying to factor these out into its own NPM package (for easier maintenance and better reuse), here called PackageA, we have arrived at a situation where the overall size of a test app, here called TestApp, is larger than it was before (when the same code existed inside the code base of the same app). TestApp is a VERY rudimentary app which basically just showcases some (but not all) parts of the components in PackageA, formerly with the components inside the project itself, and now with this part removed and instead imported from privately published PackageA.

            Sizes of initial JS chunks before factoring out PackageA with components from TestApp ("main" is assumed to be code from the project itself and the other chunk is believed to hold dependencies):

            • Gzipped: "main" chunk ~ 31 kB, chunk with external dependencies ~ 193 kB (from output after building the app)
            • Unzipped: "main" chunk ~ 93 kB, chunk with external dependencies ~ 653 kB (from browser)

            Sizes after factoring out PackageA from TestApp:

            • Gzipped: main chunk ~ 22 kB, chunk with external dependencies ~ 215 kB (from output after building the app)
            • Unzipped: main chunk ~ 57 kB, chunk with external dependencies ~ 745 kB (from browser)

            As can be seen, the overall size increases with 13 kB gzipped and 56 kB unzipped. This corresponds to an increase of ~ 6% gzipped and ~ 8% unzipped. This is not insanely much but I would still expect them to be somewhat similar.

            Further information
            • The contents of PackageA is published as es6 modules to allow for tree-shaking which seem to work properly since unused parts of PackageA are not emitted into the output chunks of TestApp.
            • Minification of PackageA is done by UglifyJS prior to publishing using both --compress and --mangle options.
            • Source maps are not included in the source files of PackageA but only available separately.
            • The only packages listed under dependencies in PackageA's package.json are NOT used anywhere else in TestApp and were subsequently removed from the TestApp's package.json at the same time as they were added to PackageA's package.json. The same versions were used. All other dependencies of PackageA are listed under peerDependencies.
            • All sizes were verified after deleting the node_modules folder and running a fresh install of dependencies.
            • The contents of PackageA is exactly the same as the deleted folder from TestApp with the exception of an added index.ts page which exports the contents of the other files. This file is < 3 kB unzipped in size.

            What could be possible sources of this increase in size and where could we start looking? Perhaps this increase might lie in how the code is transpiled in the package and that create-react-app is somehow able to do this more efficiently for code included in the project itself than for imported code. I know this is a tough question that might have many answers and that is hard to reply to.

            This is the tsconfig.json used in the factored out PackageA:

            ...

            ANSWER

            Answered 2021-Nov-14 at 16:35

            I understand that this questions might be highly dependant on the situation you're in but still thought I'd share my process.

            Measuring sizes

            Usually when you build, your framework outputs the sizes of the built artifacts. In the case of create-react-app, these sizes seem to be the size of the gzipped versions.

            You may also check your browser dev tools and note the sizes of the downloaded bundles which are typically NOT the gzipped sizes but the actual sizes.

            When factoring something out or doing some sort of comparison, take notice of the different sizes before the change and after the change. Given some sort of intuition as to how these sizes should change evaluate if this is the case or not.

            Analyzing the bundle

            With NextJS you may use @next/bundle-analyzer, in most other cases you may use source-map-explorer. The latter uses source maps to map bundled code to sources; if the source itself has source maps, then these sources are used, otherwise you will see references to node_modules. With source-map-explorer, it might be worth both looking into the visual representation as well as the json representation since, with a lot of sources, the visual representation might suppress the participation of a certain component or library which the json representation will not.

            With source-map-explorer you may make some valuable comparisons between different versions of an app.

            Analyzing particular cases of source code to production code

            After establishing with, for example, source-map-explorer that some source code expands more in some context that in another, you may want to research the issue further. Using source maps (either in development mode or in production mode if you have them available there), you may want to track the imprint of a certain portion of source code in the output bundle. A lot of browsers support mapping bundled code to source code (given source maps) but not all allow you to do the opposite. Firefox, however, has this feature and it allows you to, given bundled code, view the source code and vice versa. This is very useful when you're trying to track what some source code actually results in in the output.

            What about my use-case?

            Well, the following is a list of what caused the increased size in my case:

            • I imported from an index in my package and the index imported all of the exports of the package. This should not be a problem with esm modules, but without the sideEffects: false flag in package.json there were some ambiguities. Even though the unused sources from MY package were not added to the output bundle, some indirect dependencies could not be ruled out as not having side effects, so these were added to the bundle, even though the component that imported them were not even used. Adding sideEffects: false to the package.json of my package solved this and reduced the package size.

            • When keeping the components in my main project that was bundled using create-react-app, some convenience methods added by Babel in all transpiled files were removed thanks to the presence of @babel/plugin-transform-runtime plugin. This plugin removes these convenience methods, given that some Babel runtime was guaranteed to be present when running these files (from which they could be imported instead). When the same configuration was used for the factored out components, the size shrank even more.

            • Finally, at the time of this writing, the tsc compiler seem to output more verbose code than Babel (see TypeScript: tsc transpiles jsx to more verbose code than babel). When transpiling the package I first used tsc and after started using Babel, the size shrank even more.

            All in all, with the above changes, the output ended up being just 1.7 kB larger (unzipped) than before the refactoring which was a both understandable and acceptable result.

            Source https://stackoverflow.com/questions/69493551

            QUESTION

            Slow rollup.js bundling after copying in a 3rd-party library
            Asked 2021-Nov-10 at 15:02

            I'm using https://shoelace.style (in my Svelte project), and following the example config in shoelace docs, I added a copy() plugin to my rollup.config.js, copying it to public/vendor/shoelace:

            ...

            ANSWER

            Answered 2021-Oct-30 at 14:07

            I'm using svelte with codeigniter as well and there is a simpler way to include your css framework:

            1. List item add the stylesheet to the view (layout) header and the script to its footer just above the build of svelte's script file (if you are going to use shoelace in the whole project).
            2. add both to if you want to target only one page (even though you can also do that from the controller before loading the view to target certain pages).
            3. you can add it by installing npm i svelte-preprocess node-scss then include the scss file of you css framework and just inport the js file (and also you can do that using your global stylesheet using scss).

            Source https://stackoverflow.com/questions/69777862

            QUESTION

            How to distribute the NodeJS library written in TypeScript for both BrowserJS and NodeJS with available Webpack's three shaking?
            Asked 2021-Oct-29 at 21:17

            Like lodash, the library @yamato-daiwa/es-extensions suggests the common functions for both BrowserJS and NodeJS, but unlike lodash it has single main file index.js with re-exports.

            Requirements

            This library:

            1. Must work in browser environment with Webpack (reached ✔️)
            2. Must make available the Webpack's tree shaking (by other words, the cutting off of the unused functionality on production building) for BrowserJS where each kilobyte on count (reached ✔️).
            3. Must work in NodeJS environment.
            4. Must work with ts-node
            Main problem

            The conflicting point is the modules type. To make the Webpack's tree shaking available, the ES modules are required, but currently NodeJS supports CommonJS modules only, and in ts-node the ES modules support is limited (especially in the library exporting case).

            What we have is:

            Modules type BrowserJS (Webpack) Tree shaking NodeJS ts-node CommonJS Yes No Yes Yes ES20XX Yes Yes No Limited

            Because the tree shaking is critical for BroswerJS, it's already been decided to distribute the library by ES2020 modules. But this way, the support for NodeJS and ts-node will be lost.

            Even if to build the NodeJS application with Webpack where it's not recommended to bundle the NodeJS libraries (webpack node modules externals is being used to exclude them), application will crush if don't add the @yamato-daiwa/es-extensions with it's ES modules to excluding of webpack node modules externals.

            Repro

            In this repro, npm run "Webpack:ProductionBuild" will build the files BrowserJS.js and NodeJS.js for appropriate environment. Because the source code using isUndefined function of "@yamato-daiwa/es-extensions" library only, in BrowserJS.js must not be any other functionality (Webpack's tree shaking):

            ...

            ANSWER

            Answered 2021-Oct-29 at 21:17

            The "main" entry in a package.json file should always be in commonjs format. The "module" entry should always be es modules. Right now, you have "main" pointing to es modules, which will not be resolved properly (your ts-node error, for example).

            Generally, if you want to give consumers the option, you would create 2 builds in the distributable.

            (you'll need to remove the comments in these json files)

            Source https://stackoverflow.com/questions/69502804

            QUESTION

            Fundamental Understanding of Node JS in the front end
            Asked 2021-Oct-26 at 01:18

            Some things to know:

            • I understand how to make a HTML / CSS / JS website.
            • I understand how to make a Node JS app and host it on Heroku

            I encountered a problem that was very confusing and I still working it out. I am making a firebase project using their latest tree-shaking V9 SDK

            import { initializeApp } from 'firebase/app';

            I understand Node JS is meant for backend (it can't be run in a browser) so how am I supposed to "build" this into something that I can reference in a script tag? I've heard of webpack but that requires you to run npm run build so how is that practical in any way? That would mean every change I make I would have to build it?

            Developer Testing:

            How would one live preview this Node JS app on a localhost if Node JS can't be run in a browser? I would live to be able to preview this Node JS app and quickly make changes if that's possible.

            ...

            ANSWER

            Answered 2021-Oct-26 at 01:18

            I've heard of webpack but that requires you to run npm run build so how is that practical in any way? That would mean every change I make I would have to build it?

            Yes, that's the general idea. You make changes to script files on your local machine (or network), and then in order to see the changes take effect, you rebuild the app so that a new bundle is generated. This bundle can then be hosted on your web server or development server, and once it's there, you can refresh the page to see the differences.

            But almost all of this can be automated, resulting in it not really being much of a chore at all.

            • Nodemon is a popular tool that watches a directory for changes and can run Node scripts when a change is detected. With it, you could, for example, make a change to a file, and then it'll automatically rebuild your app.
            • For Webpack in particular, there's webpack-dev-server, which can automatically refresh a page when the app gets rebuilt.

            So, during development, the workflow can be as simple as - make a change, then alt-tab to your browser (hosting the app on localhost) to look at the changes.

            Bundles built for the purpose of eventually hosting them on the front-end can easily incorporate Node modules - the build process can take the code from the module, and the bundle produced can include that code. This sort of thing is extraordinarily common.

            Source https://stackoverflow.com/questions/69716356

            QUESTION

            How to provide Webpack tree-shaking for the usage of library distributing as ES20XX-modules
            Asked 2021-Sep-29 at 05:33

            Unfortunately, there were not the working solution for the question How to setup the TypeScript compiler for the library so that the unused modules will be cut off by Webpack in the dependents projects? (for the Sep. 2021). The solution suggested by Mr. Craig Hicks works only locally and can not be used for the distributable library (I'll explan the details below).

            However, from the Mr. Hicks's answer I knew that to make Webpack three-shaking available it's required to distribute the library as ES modules. It makes the issues for usage with Node.js native and ts-node, but I afraid I will be downoved if try to consider all of these problems in single question.

            Target

            The target library @yamato-daiwa/es-extensions has a lot of functionality and even in big applications a part of it will not be used. Theoretically, the Webpack's three shaking could cut off the unused functionality, but actually it works with huge limitations as it will be shown in experiments below.

            In the sample below, I am expecting that only isUndefined function will be bundled and any other functionality will NOT be:

            ...

            ANSWER

            Answered 2021-Sep-29 at 05:33

            It appears that declaring "sideEffects": false is the responsibility of each package an application consumes, so setting it in the application's root package.json isn't enough.

            The package.json of @yamato-daiwa/es-extensions needs to include "sideEffects": false, so applications know that package is side-effect free. I tried this in your first example repo, and the final build gave me the expected:

            Source https://stackoverflow.com/questions/69322424

            QUESTION

            Can I ask any philosophical reason for using (or not using) enum in Typescript (and string union type)
            Asked 2021-Aug-14 at 11:17

            These days I learned the concept of enum and const enum in Typescript and I got confused. I understood that const enum will be transpiled into simple values while the other not. I also understood that some feature differences between using string union type and plain enum (like iteration).

            But I can't comprehend when and why I should (not) use (const) enum. I think iteration on enum is not that general, and it's hard to predict whether they'll use it or not.

            There is a post (which is written in Korean so sorry for that) that "tree-shaking cannot optimize transpiled enum since they are IIFE". (Link)

            Than should I just use const enum without any hesitation, or is there any more pros and cons using the other alternative: string union type.

            TLDR

            1. If const enum is more lightweighted than enum, is there any practical reason to use enum?
            2. I already know Babel can't work with const enum. In that case, why someone uses enum rather than string union type even if they don't iterate over it.
            ...

            ANSWER

            Answered 2021-Aug-14 at 11:17

            I believe that enums camed to TypeScript from C#. In general numerical enums in TypeScript are unsafe. Consider this example:

            Source https://stackoverflow.com/questions/68782509

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install tree-shaking

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/thelgevold/tree-shaking.git

          • CLI

            gh repo clone thelgevold/tree-shaking

          • sshUrl

            git@github.com:thelgevold/tree-shaking.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular JavaScript Libraries

            freeCodeCamp

            by freeCodeCamp

            vue

            by vuejs

            react

            by facebook

            bootstrap

            by twbs

            Try Top Libraries by thelgevold

            angular-samples

            by thelgevoldTypeScript

            rxjs-socket.io

            by thelgevoldTypeScript

            ui-router-ngupgrade

            by thelgevoldTypeScript

            angular-lazy-load

            by thelgevoldJavaScript

            angular-wasm-sample

            by thelgevoldTypeScript