Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Bundle Loader

License

NotificationsYou must be signed in to change notification settings

webpack-contrib/bundle-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npmnodedepstestscoveragechat

! NO LONGER MAINTAINED !

This module is deprecated and will no longer be maintained.

In most cases, you can replace the functionality by usingdynamic import instead:

index.js

import(/* webpackChunkName: "my-chunk-name" */'./file.bundle.js').then(bundle=>{// Doing something with `bundle`console.log(bundle)});

This code lazy loading imports and exports values fromfile.bundle.js and creates a chunk from this module with the namemy-chank-name


Bundle Loader

Bundle loader for webpack

Install

npm i bundle-loader --save

Usage

webpack.config.js

module.exports={module:{rules:[{test:/\.bundle\.js$/,use:'bundle-loader'}]}}

The chunk is requested, when you require the bundle.

file.js

importbundlefrom'./file.bundle.js';

To wait until the chunk is available (and get the exports)you need to async wait for it.

bundle((file)=>{// use the file like it was requiredconstfile=require('./file.js')});

This wraps therequire('file.js') in arequire.ensure block

Multiple callbacks can be added. They will be executed in the order of addition.

bundle(callbackTwo)bundle(callbackThree)

If a callback is added after dependencies were loaded, it will be called immediately.

Options

NameTypeDefaultDescription
lazy{Boolean}falseLoads the imported bundle asynchronously
name{String}[id].[name]Configure a custom filename for your imported bundle

lazy

The file is requested when you require thebundle-loader. If you want it to request it lazy, use:

webpack.config.js

{loader:'bundle-loader',options:{lazy:true}}
importbundlefrom'./file.bundle.js'bundle((file)=>{...})

ℹ️ The chunk is not requested until you call the load function

name

You may set name for a bundle using thename options parameter.Seedocumentation.

webpack.config.js

{loader:'bundle-loader',options:{name:'[name]'}}

⚠️ chunks created by the loader will be named according to theoutput.chunkFilename rule, which defaults to[id].[name]. Here[name] corresponds to the chunk name set in thename options parameter.

Examples

importbundlefrom'./file.bundle.js'

webpack.config.js

module.exports={entry:{index:'./App.js'},output:{path:path.resolve(__dirname,'dest'),filename:'[name].js',// or whatever other format you wantchunkFilename:'[name].[id].js',},module:{rules:[{test:/\.bundle\.js$/,use:{loader:'bundle-loader',options:{name:'my-chunk'}}}]}}

Normal chunks will show up using thefilename rule above, and be named according to their[chunkname].

Chunks frombundle-loader, however will load using thechunkFilename rule, so the example files will producemy-chunk.1.js andfile-2.js respectively.

You can also usechunkFilename to add hash values to the filename, since putting[hash] in the bundle options parameter does not work correctly.

Maintainers


Juho Vepsäläinen

Joshua Wiens

Michael Ciniawsky

Alexander Krasnoyarov

About

Bundle Loader

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors19


[8]ページ先頭

©2009-2025 Movatter.jp