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

  • 相关阅读:
    面试1
    初级算法-数组1
    程序员常用单词
    SpringBoot
    JDBC
    animate.css 实现 网页滚动指定位置添加动画
    解决打包上线缓存问题
    组件之间双向绑定
    按照给定数组排序原数组
    扩展运算符... 的使用
  • 原文地址:https://www.cnblogs.com/chucklu/p/14177488.html
Copyright © 2011-2022 走看看