40

vue-thread-loader: Speed up your build process

 5 years ago
source link: https://www.tuicool.com/articles/aMjumya
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Vue Thread Loader

Improve your build speed

vue-thread-loader injects the thread-loader into your build chain to speed things up.

Installation

Install it using npm or yarn:

yarn add vue-thread-loader --dev
npm i vue-thread-loader --save-dev

Usage

vue-thread-loader exposes a single function which receives a configuration object. Pass this to your vue.config.js configureWebpack option.

vue.config.js

const vueThreadLoader = require('vue-thread-loader');

module.exports = {
    configureWebpack: vueThreadLoader({
        silent: Boolean // Default: true -> Supress log
        filter: Function // Default: null -> A function which reveices the rule / current env and returns a falsy value if this rule should be skipped
        mode: String // Default: 'any' -> Gets be compared to NODE_ENV and decides where the thread-loader should be injected. Use 'all' to allow all.
    })
}

Or use it in-line:

const vueThreadLoader = require('vue-thread-loader');

module.exports = {
    configureWebpack(config) {
        // Your other stuff
        vueThreadLoader()(config);
    }
}

Examples

No debug log of vueThreadLoader. thread-loader gets injected into every chain and on any NODE_ENV.

module.exports = {
    configureWebpack: vueThreadLoader()
}

Print debug log of vueThreadLoader. thread-loader gets injected into every chain but only on production mode.

module.exports = {
    configureWebpack: vueThreadLoader({
        mode: 'production', 
        silent: false
    })
}

No debug log of vueThreadLoader. thread-loader gets only injected into the vue chain and production mode.

module.exports = {
    configureWebpack: vueThreadLoader({
        mode: 'production', 
        filter(rule, env) {
            return rule.test.toString().includes('vue')
        }
    })
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK