jerrybabah / my_video_playground

video api를 이용해서 이것 저것 해보는 레포입니다.
0 stars 0 forks source link

webpack 기본 #2

Open jerrybabah opened 4 years ago

jerrybabah commented 4 years ago

설치

$ yarn add --dev webpack webpack-cli

웹팩의 역할

entry 파일을 시작으로 dependency graph를 만들어 프로젝트의 모든 모듈을 몇 개의 번들 파일로 만든다.

webpack.config.js 예시

const path = require('path');

const HTMLWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
  entry: './src/main.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name].js',
    // chunkFilename: 'chunk.js',
    // publicPath: '/',
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, 'css-loader'],
      },
      {
        test: /\.(js|ts)$/,
        use: {
          loader: 'babel-loader',
        },
      },
    ],
  },
  plugins: [
    new HTMLWebpackPlugin({
      template: './public/index.html',
    }),
    new MiniCssExtractPlugin({
      fileName: 'style.css',
    }),
  ],
}

기본 개념

entry

{
  entry: string,
}

output

{
  output: {
    path: string,
    filename: string,
  },
}

module

{
  module: {
    rules: [
      // loader
      {
        test: RegExp,
        use: string | string[] | { loader: string, options: object },
      },
    ],
  },
}

plugins

{
  plugins: [
    new InstalledPlugins({...options}),
  ],
}