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

  • 相关阅读:
    C# 监测每个方法的执行次数和占用时间(测试1)
    C# 依赖注入那些事儿
    SQL Server GROUP BY 后 拼接 字符串
    C# 根据Excel生成树
    C# 反射赋值
    C# 集合转换为DataTable
    Oracle 未能加载文件或程序集Oracle.DataAccess
    MySQL 各种主流 SQLServer 迁移到 MySQL 工具对比
    平衡树
    数据结构优化dp
  • 原文地址:https://www.cnblogs.com/chucklu/p/14177488.html
Copyright © 2011-2022 走看看