π
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
$ 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
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,
},
};
https://webpack.js.org/configuration/entry-context/#entry
https://webpack.js.org/configuration/output/#outputpath
https://webpack.js.org/configuration/output/#outputclean
π 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"],
},
],
},
};