webpackjs 打包器、安装、打包...

set1:安装
1.全局安装webpack:npm install webpack -g(简写:npm i webpack -g)
2.全局安装webpack-cli:npm install webpack-cli -g

set2:使用
1.生成node_modules:npm install webpack --save-dev(简写:npm i webpack -D)
2.执行npm init (默认项目配置请使用:npm init -y)
3.package.json配置
在package.json文件 "scripts" 中增加 "build" : "webpack --progress --colors"

4.官网例子https://www.webpackjs.com/

demo-01
    node_modules
    package-lock.json
    package.json
    src
        index.js
        bar.js
    page.html
    webpack.config.js

文件:src/index.js
代码:
    import bar from './bar';
    bar();

文件:src/index.js
代码:

文件:src/bar.js
代码:
    export default function bar() {
      //
    }

文件:webpack.config.js
代码:
    const path = require('path');

    module.exports = {
      entry: './src/index.js',
      output: {
          path: path.resolve(__dirname, 'dist'),
        filename: 'bundle.js'
      }
    };

文件:page.html
代码:
    <!doctype html>
        <html>
            <head>
                ...
            </head>
        <body>
            ...
            <script src="dist/bundle.js"></script>
        </body>
    </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值