Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

npm node

Fork Loader

base on worker-loader

This loader registers the script as fork code

Install

npm i -D webpack-fork-loader

Usage

Inlined

App.js

import CProcess from 'webpack-fork-loader!./fork.js';

Config

webpack.config.js

{
  module: {
    rules: [
      {
        test: /\.fork\.js$/,
        use: { loader: 'webpack-fork-loader' }
      }
    ]
  }
}

App.js

import CProcess from './file.fork.js';

const process = new CProcess();

process.send({ a: 1 });
process.on('message', (message) => {});

Options

Name Type Default Description
name {String} [hash].fork.js Set a custom name for the output script
publicPath {String} null Override the path from which fork scripts are downloaded
evalPath {Boolean} null if publicPath is treat as a static String

name

To set a custom name for the output script, use the name parameter. The name may contain the string [hash], which will be replaced with a content dependent hash for caching purposes. When using name alone [hash] is omitted.

webpack.config.js*

{
  loader: 'webpack-fork-loader',
  options: { name: 'ForkName.[hash].js' }
}

publicPath

Overrides the path from which fork scripts are downloaded. If not specified, the same public path used for other webpack assets is used

webpack.config.js

{
  loader: 'webpack-fork-loader'
  options: { publicPath: '/scripts/fork/' }
}

evalPath

if wants to get dynamic publicPath like '__dirname', you should set evalPath = true

webpack.config.js

{
  loader: 'webpack-fork-loader'
  options: {  publicPath: '__dirname + "/"', evalPath: true }
}

License

MIT

About

webpack-fork-loader

Topics

Resources

License

Releases

No releases published

Packages

No packages published