Webpack-targets (Build target)

Source: Internet
Author: User

Build Target (Targets)

Because both the server and browser code can be written in JavaScript, Webpack provides a variety of build targetsthat you can set in your webpack configuration.

Webpack target properties are not output.libraryTarget confused with attributes. For output more information about properties, see our guide.
usage

To set a target property, you only need to set the target value in your webpack configuration.

Webpack.config.js

Module.exports = {  'node'};

In the example above, the use node of Webpack will be compiled for the class node.js"environment (using node. js require instead of using any built-in modules (such as fs or path ) to load chunk).

Each target has a variety of deployment (deployment)/environment (environment) specific add-ons to support its needs. View the available values for target.

further expansion for other popular target values
multiple Target

Although Webpack does not support the target passing of multiple strings, you can create a homogeneous library by packaging two separate configurations:

Webpack.config.jsvarPath = require ('Path‘);varServerconfig ={target:‘node‘, Output: {path:path.resolve (__dirname,‘Dist‘), FileName:‘Lib.node.js‘  }  //... ..};varClientConfig ={target:‘Web‘,//<=== default is ' Web ', can omitoutput: {path:path.resolve (__dirname,‘Dist‘), FileName:‘Lib.js‘  }  //... ..};module.exports= [Serverconfig, ClientConfig];

The above example will be dist created under your folder lib.js and the lib.node.js file.

Resources

From the options above, you can see that there are several different deployment targets to choose from. Here is a list of examples and resources you can refer to.

    • Compare-webpack-target-bundles: A large number of resources for "testing and viewing" different Webpack target . There are also a number of bug reports.
    • Boilerplate of electron-react application: A good example of the process of building a Electron main process and rendering process.

Webpack-targets (Build target)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.