npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

entry-chunk-webpack-plugin

v3.0.0

Published

A webpack plugin that splits one entry file into multiple files and add them to entry of webpack.

Downloads

6

Readme

entry-chunk-webpack-plugin

A webpack plugin that splits one entry file into multiple files and add them to entry of webpack.

Install

npm i -D entry-chunk-webpack-plugin

Usage

In your webpack configuration (webpack.config.js):

const EntryChunkWebpackPlugin = require('entry-chunk-webpack-plugin');
const LibraryExtendWebpackPlugin = require('library-extend-webpack-plugin');

module.exports = {
    mode: "production",
    entry: {
        example: './src/index.ts',
    },
    output: {
        library: "LIB",
        libraryTarget: "umd",
        filename: '[name].js'
    },
    //...
    plugins: [
        new EntryChunkWebpackPlugin({
            chunkConfig: [{
                name: 'example.base',
            }, {
                name: 'example.extend',
                modules: ['RichEditor', 'ReactCropper']
            }],
        }),
        new LibraryExtendWebpackPlugin({
            exclude: function (fileName) {
                return !/\.[tj]s$/i.test(fileName) || /example(\.base)*(\.min)*\.js/.test(fileName);
            }
        }),
    ]
}

Entry File: index.ts

export { default as Avatar } from './components/avatar/index';

export { default as Button } from './components/button/button';

export { default as RichEditor } from './components/rich-editor/index';

export { default as ReactCropper } from './components/react-cropper/index';

Output Bundle

It will output 3 files

example.js ({ Avatar, Button, RichEditor, ReactCropper })
example.base.js ({ Avatar, Button })
example.extend.js ({ RichEditor, ReactCropper })

Avatar and Button will be packaged to example.base.js.
RichEditor and ReactCropper will be packaged to example.extend.js.

Function Avatar, Button, RichEditor and ReactCropper are added to global library LIB.
And LIB.Avatar, LIB.Button, LIB.RichEditor and LIB.ReactCropper work well.

Options

mode

Its value can be 'add' or 'replace' or ''. The default value is add.

'add': means will add chunk file to entry.
'replace': means will remove original entry file, and add chunk file to entry.
'': means will not add chunk file to entry.

min

Its value must be boolean or 'both'. The default value is false.

true: it will add [name].min.js to entry.
false: it will add [name].js to entry.
'both': it will both add [name].js and [name].min.js to entry.

chunkConfig

Its value must be Array. You need to config it to split entry file into multiple files as example.

exclude

You can skip entry file by exclude: ({name, path}) => boolean

Example of usage on the Browser

In the browser:

<script src="https://cdn.xx.com/example.base.js"></script>
<script src="https://cdn.xx.com/example.extend.js"></script>

If you do not use the module (RichEditor and ReactCropper) in example.extend.js, you can only add example.base.js to html. Because in the example, library-extend-webpack-plugin is used to package example.extend.js into an extension library.

<script src="https://cdn.xx.com/example.base.js"></script>