webpack——entry和output

60 阅读1分钟

entry和output

webpack.config.js | Configuration | webpack

  1. 创建webpack.config.js文件
  2. 写入以下代码
    const path = require('path');
    
    module.exports = {
      mode: 'development',
      entry: './foo.js',
      output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'foo.bundle.js',
      },
    };
    
    代码含义:
    1. 将当前目录下的foo.js进行转译
    2. 新建一个dist目录
    3. 转译之后的文件放在dist目录
    4. 转译之后的文件名为foobundle.js

示例

const path = require('path');

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

动画.gif