Skip to content

ka2yuki/env_webpack_NOTE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webpack ENVs

Webpack環境の作成

環境:WSL

nvm -v
> 0.39.7
node -v
> v20.16.0

pakege.json作成 ~ 開発サーバーまで

npm init -y
npm i -D webpack webpack-dev-server webpack-cli @webpack-cli/generators
npm install --save-dev css-loader

npm audit fix
npm audit
echo "==========================" && sleep 2
npm fund

npx webpack init # webpack.config.js作成
npx webpack serve # open localhost:devserver.

Documentation

webpack --config prod.config.js

Error log

  • --template=default でエラー on WSL
    • nvmを使用することにしたら解決しました。

ハマったポイント

webpack5

  • 開発サーバーが立ち上がらない: webpack-dev-serverをインストールする必要がある。
    • エラーメッセージ:[webpack-cli] For using 'serve' command you need to install: 'webpack-dev-server' package.
  • HotReloadされない: DevServer
    • webpack.config.js の config.entryのファイルをwatch しているが バンドルされない他ファイルを編集していた。。

Points

webpack.config.js

const path = require("path");

Nodejs.API: path: https://nodejs.org/api/path.html

const HtmlWebpackPlugin = require("html-webpack-plugin");

https://webpack.js.org/plugins/html-webpack-plugin/

// ⚠️ Since webpack v4 the extract-text-webpack-plugin should not be used for css.  Use this below instead.
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); 
// config.plugin.push( new MiniCssExtractPlugin() );

https://webpack.js.org/plugins/mini-css-extract-plugin/

const WorkboxWebpackPlugin = require("workbox-webpack-plugin");
// config.plugin.push( new WorkboxWebpackPlugin.GenerateSW() );

workbox-webpack-plugin | google🔍
https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin?hl=ja

Bundle画像サイズの制限

  module: {
    rules: [
      {
        parser: {
          dataUrlCondition: {
            maxSize: 4 * 1024,
          }
        }}]}

https://webpack.js.org/configuration/module/#ruleparserdataurlcondition

JavaScript compiler.

構文チェック

todo read:books:

About

Webpack環境の学習。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published