webpack-promise-catch-loader

0.0.6 • Public • Published

webpack-promise-catch-loader

根据 promise-catch-loader 修改而来

为你的promise添加catch。

具体使用方法查看下方example,或者 example

options

catchCode

自定义catch方法的函数参数的源代码

example

// webpack.config.js
const webpackPromiseCatchLoader = require('webpack-promise-catch-loader')

{
  test: /\.js$/,
  use: [
    {
      loader: webpackPromiseCatchLoader,
      options: {
        catchCode: `
          console.log(error);
          fetch(\`https://example.com'/log?message=\${error.message}\`).then(() => {})
        `
      }
    }
  ]
}

Before

// example 1
new Promise(resolve => {
  resolve(1)
}).then(res => {
  console.log(1, res)
})


// example 2
new Promise(resolve => {
  resolve(1)
}).then(res => {
  console.log(1, res)
}).then(res => {
  console.log(2, res)
})

// example 3
new Promise(resolve => {
  resolve(1)
}).then(res => {
  console.log(1, res)
}).catch(error => {
  console.log(error)
})

After

/* 0 */
/***/ (function(module, exports) {

// example 1
new Promise(resolve => {
  resolve(1)
}).then(res => {
  console.log(1, res)
}).catch(error => {
  console.log(error);
  fetch(`https://example.com'/log?message=${error.message}`).then(() => {})
})


// example 2
new Promise(resolve => {
  resolve(1)
}).then(res => {
  console.log(1, res)
}).then(res => {
  console.log(2, res)
}).catch(error => {
  console.log(error);
  fetch(`https://example.com'/log?message=${error.message}`).then(() => {})
})

// example 3
new Promise(resolve => {
  resolve(1)
}).then(res => {
  console.log(1, res)
}).catch(error => {
  console.log(error)
})

/***/ })

Readme

Keywords

none

Package Sidebar

Install

npm i webpack-promise-catch-loader

Weekly Downloads

1

Version

0.0.6

License

ISC

Unpacked Size

26.2 kB

Total Files

6

Last publish

Collaborators

  • lyulelee