Concepts
- Entry
- Output
- Loaders
- Plugins
- Mode
- Browser Compatibility
Entry
webpack.config.js
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
}
};
Output
webpack.config.js
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
}
};
Loaders
- test 속성은 변환되어야하는 파일 또는 파일들을 나타낸다
- use 속성은 변환을 수행하는데 사용해야만 하는 loader 를 나타낸다.
webpack.config.js
const path = require('path');
module.exports = {
output: {
filename: 'my-first-webpack.bundle.js'
},
module: {
rules: [
{ test: /\.txt$/, use: 'raw-loader' }
]
}
};
위의 설정에서 정의된 rules 속성은 두가지 프로퍼티가 요구된다. test 와 use
이것은 webpack의 컴파일러에게 다음과 같은 의미를 전달한다
헤이 webpack~
import 나 require() 의 경로에서 .txt 로 리졸브되는 경로를 발견하면,
번들에 추가하기 전에 raw-loader 를 사용하여 변환해줘
Plugins
webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
const webpack = require('webpack'); //to access built-in plugins
module.exports = {
module: {
rules: [
{ test: /\.txt$/, use: 'raw-loader' }
]
},
plugins: [
new HtmlWebpackPlugin({template: './src/index.html'})
]
};
위의 예에서는, html-webpack-plugin 이 모든 생성되는 번들을 자동적으로 인젝팅하여 어플리케이션에 HTML 파일을 생성한다.
webpack은 많은 플러그인을 제공한다.
webpack 설정에서 플러그인의 사용은 간단하지만, 좀 더 유심히 봐야할 경우가 있다. Learn more about them here.
Mode
Learn more about the mode configuration here and what optimizations take place on each value.
Browser Compatibility
'WEB > Webpack' 카테고리의 다른 글
webpack 이란 무엇인가 (1) | 2019.01.15 |
---|