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

ensure-chunk-loader

v3.0.1

Published

Get the corresponding page resource and the corresponding script resource under the folders, and return the router

Downloads

3

Readme

ensure-chunk-loader

Get the corresponding page resource and the corresponding script resource under the folders, and return the router

do what? and why?

In my project, the subpages are loaded by the router, but the subpages are added or reduced at any time. I don't want to manually configure a router every time I write a sub page. The router configuration I use is dynamically acquired. When I call a router, I can access corresponding sub pages. Yes, that's right. That's why I wrote this loader.

Install

npm install --save-dev ensure-chunk-loader

Usage

Project structure

app
 |-modules
 |    |-first
 |    |   |-first.html
 |    |   |-first.js
 |    |-second
 |        |-second.html
 |        |-second.js
 |-index.html
 |-index.js

webpack.config.js

var path = require("path");
var HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports={
    context:path.join(__dirname,"app"),
    entry:"./index.js",
    output:{
        path:path.join(__dirname,"dist"),
        filename:"[name].js",
        chunkFilename:"[name].js"
    },
    module: {
        rules: [
            {
                test: /\.(html)$/,
                use: {
                  loader: 'html-loader'
                }
            }
        ]
    },
    plugins: [
        new HtmlWebpackPlugin({
            template:path.join(__dirname,"app","index.html"),
            filename: '[name].html',
        })
    ]
}

index.js

var router = require("ensure-chunk-loader?pattern=./modules/*/&page-extname=html&script-extname=js!");
router["./modules/first"]().then(function(chunk){
    console.log(chunk["page"]());
    console.log(chunk["script"]());
});

notes

Although this is a'loader', it does not need to be passed in the source, so the parameters introduced in the'require' end with "!".

To use this'loader', you must ensure that the name of folders are the same as the file name of the page file and the script file (excluding the suffix). For example, the folder name is called'demo', so the page name must be called' demo.suffix '(suffix is html, jade and so on). The name of the script must be called'demo.suffix' (suffix is js, jsx, ts and so on).

Options

|name|type|default|description
|:--:|:--:|:-----:|:----------| |pattern|string|undefined|Resource path| |options|object|undefined|glob options| |page-extname|string|"html"|Page suffix| |script-extname|string|"js"|Script suffix|

pattern:Using glob pattern,it is the relative path to the value of context in webpack.Pattern is the glob of the path of the resource folder, so it ends with "/"

the router

when use this loader,the return value I call 'router'. the 'router' is a Object,and its structure is like this:

{
  "./modules/first":fn,
  "./modules/second":fn,
  "other key(The path of a folder relative to the context)":fn
}

the fn's return value is a instance of Promise,its resolve's parameter is {page:page,script:script} whitch equivalent to a similar as like {page:function(){return require("./modules/first/first.html")},script:function(){return require("./modules/first/first.js")}}