当前位置: 移动技术网 > IT编程>开发语言>JavaScript > webpack初起步

webpack初起步

2019年03月11日  | 移动技术网IT编程  | 我要评论

webpack 用于编译 javascript 模块。一旦完成,就可以通过 webpack 的 cli 或 api 与其配合交互。

首先创建一个目录,进入目录中,初始化npm 然后本地安装webpack,webpack-cli ,lodash

目录结构:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>document</title>
</head>
<body>
    <script src="bundle.js"></script>
</body>
</html>

webpack.config.js

const path = require('path');

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

package,json

{
  "name": "webpack-demo",
  "version": "1.0.0",
  "description": "",
  "private": true,
  "scripts": {
    "test": "echo \"error: no test specified\" && exit 1",
    "build": "webpack"
  },
  "keywords": [],
  "author": "",
  "license": "isc",
  "devdependencies": {
    "webpack": "^4.29.6",
    "webpack-cli": "^3.2.3"
  },
  "dependencies": {
    "lodash": "^4.17.11"
  }
}

输入npm run build

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网