zoukankan      html  css  js  c++  java
  • Getting Started webpack

    https://webpack.js.org/guides/getting-started/

    Getting Started

    webpack is used to compile JavaScript modules. Once installed, you can interact with webpack either from its CLI or API. If you're still new to webpack, please read through the core concepts and this comparison to learn why you might use it over the other tools that are out in the community.

    The minimum supported Node.js version to run webpack 5 is 10.13.0 (LTS)

    Basic Setup

    NPM Scripts

    Given it's not particularly fun to run a local copy of webpack from the CLI, we can set up a little shortcut. Let's adjust our package.json by adding an npm script:

    package.json

     {
       "name": "webpack-demo",
       "version": "1.0.0",
       "description": "",
       "private": true,
       "scripts": {
    
        "test": "echo "Error: no test specified" && exit 1"
    
        "test": "echo "Error: no test specified" && exit 1",
    
        "build": "webpack"
       },
       "keywords": [],
       "author": "",
       "license": "ISC",
       "devDependencies": {
         "webpack": "^5.4.0",
         "webpack-cli": "^4.2.0"
       },
       "dependencies": {
         "lodash": "^4.17.20"
       }
     }

    Now the npm run build command can be used in place of the npx command we used earlier. Note that within scripts we can reference locally installed npm packages by name the same way we did with npx. This convention is the standard in most npm-based projects because it allows all contributors to use the same set of common scripts.

    Now run the following command and see if your script alias works:

    $ npm run build
    
    ...
    
    [webpack-cli] Compilation finished
    asset main.js 69.3 KiB [compared for emit] [minimized] (name: main) 1 related asset
    runtime modules 1000 bytes 5 modules
    cacheable modules 530 KiB
      ./src/index.js 257 bytes [built] [code generated]
      ./node_modules/lodash/lodash.js 530 KiB [built] [code generated]
    webpack 5.4.0 compiled successfully in 1940 ms

    Custom parameters can be passed to webpack by adding two dashes between the npm run build command and your parameters, e.g. npm run build -- --color.

    Conclusion

  • 相关阅读:
    Ruby 集合数组常用遍历方法
    Git,Github和Gitlab简介和基本使用
    L1-Day14
    学习进度(2)
    求数组的子数组的最大值(文件存储)
    开学第一课博客——自我介绍
    求数组的子数组的最大值
    学习进度(1)
    java web+模板
    android开发环境配置以及测试所遇到的的问题
  • 原文地址:https://www.cnblogs.com/chucklu/p/14177488.html
Copyright © 2011-2022 走看看