> For the complete documentation index, see [llms.txt](https://ja.docs.monaca.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ja.docs.monaca.io/webpack5heno.md).

# Webpack5への更新

### NPMパッケージのアンインストール

* webpack-serveを利用している場合は、アンインストールする

```sh
npm uninstall webpack-serve --force
```

### webpack.config.js

#### 画像などのリソース関係のローディングを更新

```javascript
{
    test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?\S*)?$/,
    type: 'asset/resource',
    generator: {
        filename: 'assets/[name].[hash].[ext]'
    }
},

```

chunksortのモードの削除

#### webpackConfig.devServerと更新

```javascript
webpackConfig.devServer = {
    allowedHosts: 'all',
    port: port,
    host: host,
    devMiddleware: {
        publicPath: '/',
        stats: true
    },
    client: {
        webSocketURL: {
            pathname: "/ws",
            hostname: host,
            port: port,
            protocol: 'wss',
        },
    },
};

```

#### presetsを「@babel/preset-env」に更新

```javascript
{
    test: /\.(js|jsx)$/,
    exclude: /node_modules/,
    include: path.resolve(__dirname, 'src'),
    use: [{
        loader: 'babel-loader',
        options: {
            presets: ['@babel/preset-env']
        }
    }]
},
```

### **package.jsonの更新**

```javascript
"@babel/core": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"babel-loader": "^9.1.3",
"css-loader": "^6.8.1",
"cssnano": "^6.0.1",
"file-loader": "^6.2.0",
"html-loader": "^4.2.0",
"html-webpack-plugin": "^5.5.3",
"mini-css-extract-plugin": "^2.7.6",
"progress-bar-webpack-plugin": "^2.1.0",
"style-loader": "^3.3.3",
"vue-loader": "15.9.8",
"vue-template-compiler": "2.6.14",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1",
"yargs": "^17.7.2"
```

package.jsonの scriptsタグについて、devを次の内容に更新

```
"dev": "webpack serve --open",
```

### POSTCSSのアンインストール

package.jsonから下記のパッケージを削除します。また、postcss.configファイルを削除します。

```javascript
"postcss": "^8.4.7",
"postcss-loader": "^6.2.1",
"postcss-preset-env": "^7.4.1",
"postcss-url": "^10.1.3",
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ja.docs.monaca.io/webpack5heno.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
