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

    npm init -y
    npm install webpack webpack-cli —save-dev
    npm install —save lodash

    1. webpack-demo
    2. |- package.json
    3. |- webpack.config.js
    4. |- /dist
    5. |- main.js
    6. |- index.html
    7. |- /src
    8. |- index.js
    9. |- /node_modules
    1. <!-- /dist/index.html -->
    2. <!doctype html>
    3. <html>
    4. <head>
    5. <title>Getting Started</title>
    6. </head>
    7. <body>
    8. <script src="main.js"></script>
    9. </body>
    10. </html>
    1. // /webpack.config.js
    2. const path = require('path');
    3. module.exports = {
    4. entry: './src/index.js',
    5. output: {
    6. filename: 'main.js',
    7. path: path.resolve(__dirname, 'dist')
    8. }
    9. };
    1. // /index.js
    2. import _ from 'lodash';
    3. function component() {
    4. let element = document.createElement('div');
    5. element.innerHTML = _.join(['Hello', 'webpack'], ' ');
    6. return element;
    7. }
    8. document.body.appendChild(component());

    控制台,执行webpack
    会自动生成dist文件夹,index.html页面要手动拷贝进去
    会从src中找到index.js然后“通过加工”在dist文件夹中自动生成main.js,需要你配置加载器,就会对js进行加工了