웹팩의 기본 구조
//SPA module.exports = { entry: './src/index.js' } //Multi Page Application module.exports ={ entry:{ login: './src/Login.js'; main: './src/Main.js'; } }
let path = require('path'); module.exports ={ output: { filename: 'bundle.js' path: path.resolve(__dirname, './dist') //결과: ./dist/bundle.js } }filename: '[name].bundle.js' // 결과 파일 이름에 entry 속성을 포함 filename: '[id].bundle.js' // 결과 파일 이름에 웹팩 내부적으로 사용하는 모듈 ID 포함하는 옵션 filename: '[name].[hash].bundle.js' // 매 빌드마다 고유 해시값 붙이는 옵션 filename: '[chunkhash].bundle.js' //웹팩의 각 모듈 내용을 기준으로 생성된 해시값 붙이는 옵션
module.exports = { module: { rules:[ { test: /\.css$/, use:['css-loader'] } ] } }npm install --save-dev style-loader css-loader
let webpack = require('webpack'); let HtmlWebpackPlugin = require('html-webpack-plugin); module.exports = { plugins:[ new webpack.ProgressPlugin({옵션..}), new HtmlWebpackPlugin({옵션...}) ] }npm install --save-dev html-webpack-plugin npm i -D html-webpack-plugin <!-- 축약형 -->
```js "scripts":{ "build":"webpack" }npm run build
npm init -ynpm install --save-dev webpack webpack-clinpx webpack
npx webpack --target=nodenode ./dist/main.js
npx webpack
Last updated