snipplets.dev/code/JavaScript/webpack.md

38 lines
807 B
Markdown
Raw Normal View History

2021-11-18 01:21:29 +03:00
## WebPack
2024-04-28 00:18:39 +03:00
2021-11-18 01:21:29 +03:00
`packages.json`
2024-04-28 00:18:39 +03:00
2021-11-18 01:21:29 +03:00
```json
"scripts": {
"serve": "webpack serve",
"html": "html-minifier --collapse-whitespace --remove-comments src/index.html --output dist/index.html",
"css": "csso src/styles.css --output dist/styles.css",
"build": "npm run html && npm run css && webpack --mode=production"
},
"devDependencies": {
"webpack": "^5.42.0",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2"
}
```
2024-04-28 00:18:39 +03:00
2021-11-18 01:21:29 +03:00
`webpack.config.js`
2024-04-28 00:18:39 +03:00
2021-11-18 01:21:29 +03:00
```javascript
const path = require('path');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'engine.js',
},
devServer: {
contentBase: path.join(__dirname, 'src'),
compress: false,
port: 55555,
},
};
```