λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

πŸ’¬/γ…γ……γ…Œγ…‹γ…γ…… μ±Œλ¦°μ§€

31일차

πŸ’ƒ

31일차

 

Part 8. Bundler

Ch 1. Parcel

Ch 2. Webpack

 


 

 

Ch 1. Parcel

 

 

 

 

 πŸ”— Parcel Plugin Static Files Copy  => 정적 파일 μ—°κ²°

 

https://www.npmjs.com/package/parcel-plugin-static-files-copy

 

parcel-plugin-static-files-copy

ParcelJS plugin to copy static files from static dir to bundle directory.. Latest version: 2.6.0, last published: a year ago. Start using parcel-plugin-static-files-copy in your project by running `npm i parcel-plugin-static-files-copy`. There are 7 other

www.npmjs.com

 

$ npm i -D parcel-plugin-static-files-copy
// package.json

{
	...
    "staticFiles": {
        "staticPath": "static",
    }
}

 

 

 πŸ”— Autoprefixer 

 

$ npm i -D postcss autoprefixer
// package.json

{
	...
    "browserslist": [
    	"> 1%",
    	"last 2 versions"
  	]
}
// .postcssrc.js

module.exports = {
  plugins: [require("autoprefixer")],
};

 

 

 πŸ”— Babel 

 

 

$ npm i -D @babel/core @babel/preset-env
$ npm i -D @babel/plugin-transform-runtime
// package.json

{
	...
    "browserslist": [
    	"> 1%",
    	"last 2 versions"
  	]
}
// .barbelre.js

module.exports = {
  presets: ["@babel/preset-env"],
  plugins: [["@babel/plugin-transform-runtime"]],
};

 

 

 πŸ”— CLI 

 

https://ko.parceljs.org/cli.html

 

πŸ–₯ μ»€λ§¨λ“œ 라인 μΈν„°νŽ˜μ΄μŠ€(CLI)

μ‹œμž‘ν•˜κΈ° κΈ°λŠ₯ πŸ“¦ μ• μ…‹ μœ ν˜• κ³ κΈ‰ πŸ–₯ μ»€λ§¨λ“œ 라인 μΈν„°νŽ˜μ΄μŠ€(CLI) λͺ…λ Ήμ–΄ Serve 개발용 μ„œλ²„λ₯Ό μ‹œμž‘ν•©λ‹ˆλ‹€. 앱이 μˆ˜μ •λ˜λ©΄ μžλ™μœΌλ‘œ λ‹€μ‹œ λΉŒλ“œν•˜κ³ , λΉ λ₯Έ κ°œλ°œμ„ μœ„ν•΄ λΉ λ₯Έ λͺ¨λ“ˆ ꡐ체λ₯Ό μ§€μ›ν•©λ‹ˆ

ko.parceljs.org

 

 


 

 

Ch 2. Webpack

 

 

$ npm i -D webpack webpack-cli webpack-dev-server@next
// package.json

{
	...
    "scripts": {
      "dev": "webpack-dev-server --mode development",
      "build": "webpack --mode production"
    },
}

 

 

 πŸ”— entry, output 

 

// webpack.config.js

// import
const path = require("path");

// export
module.exports = {
  // νŒŒμΌμ„ 읽어듀이기 μ‹œμž‘ν•˜λŠ” μ§„μž…μ ‘ μ„€μ •
  entry: "./js/main.js",

  // κ²°κ³Όλ¬Ό(λ²ˆλ“€)을 λ°˜ν™˜ν•˜λŠ” μ„€μ •
  output: {
    // path: path.resolve(__dirname, "dist"),
    // filename: "main.js",
    clean: true,
  },
};

$ npm run build

 

https://webpack.js.org/configuration/entry-context/#entry

 

Entry and Context | webpack

webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

webpack.js.org

https://webpack.js.org/configuration/output/#outputpath

 

Output | webpack

webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

webpack.js.org

https://webpack.js.org/configuration/output/#outputclean

 

Output | webpack

webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable of transforming, bundling, or packaging just about any resource or asset.

webpack.js.org

 

 

 πŸ”— plugins 

 

$ npm i -D html-webpack-plugin
// webpack.config.js

// import
...
const HtmlPlugin = require("html-webpack-plugin");

// export
module.exports = {
  ...

  // λ²ˆλ“€λ§ ν›„ 결과물의 처리 방식 λ“± λ‹€μ–‘ν•œ ν”ŒλŸ¬κ·ΈμΈλ“€μ„ μ„€μ •
  plugins: [
    new HtmlPlugin({
      template: "./index.html",
    }),
  ],
};

 

 

 πŸ”— 정적 파일 μ—°κ²° 

 

$ npm i -D copy-webpack-plugin
// import
...
const CopyPlugin = require("copy-webpack-plugin");

// export
module.exports = {
  ...
  
  // λ²ˆλ“€λ§ ν›„ 결과물의 처리 방식 λ“± λ‹€μ–‘ν•œ ν”ŒλŸ¬κ·ΈμΈλ“€μ„ μ„€μ •
  plugins: [
    ...
    new CopyPlugin({
      patterns: [{ from: "static" }],
    }),
  ],
};

 

 

 πŸ”— module 

 

$ npm i -D css-loader style-loader
// main.js

import "../css/main.css";
// webpack.config.js

...

// export
module.exports = {
  ...

  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"], // ⭐ μˆœμ„œ μ€‘μš”
      },
    ],
  },
};

 

 

 πŸ”— SCSS 

 

$ npm i -D sass-loader sass
// webpack.config.js

...

// export
module.exports = {
  ...

  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader", "sass-loader"], // ⭐ μˆœμ„œ μ€‘μš”
      },
    ],
  },
};

 

 

 πŸ”— Autoprefixer(PostCSS) 

 

$ npm i -D postcss autoprefixer postcss-loader
// package.json

{
	...
    "browserslist": [
    	"> 1%",
    	"last 2 versions"
  	]
}
// .postcssrc.js

module.exports = {
  plugins: [require("autoprefixer")],
};
// webpack.config.js

...

// export
module.exports = {
  ...

  module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader", "postcss-loader", "sass-loader"], // ⭐ μˆœμ„œ μ€‘μš”
      },
    ],
  },
};

 

 

 πŸ”— Babel 

 

$ npm i -D @babel/core @babel/preset-env @babel/plugin-transform-runtime
$ npm i -D babel-loader
// package.json

{
	...
    "browserslist": [
    	"> 1%",
    	"last 2 versions"
  	]
}
// .barbelre.js

module.exports = {
  presets: ["@babel/preset-env"],
  plugins: [["@babel/plugin-transform-runtime"]],
};
// webpack.config.js

...

// export
module.exports = {
  ...
  
  module: {
    rules: [
      ...
      {
        test: /\.js$/,
        use: ["babel-loader"],
      },
    ],
  },
};

 

'πŸ’¬ > γ…γ……γ…Œγ…‹γ…γ…… μ±Œλ¦°μ§€' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

33일차  (0) 2022.03.19
32일차  (0) 2022.03.18
30일차  (0) 2022.03.18
29일차  (0) 2022.03.17
28일차  (0) 2022.03.17