vue init webpack-simple 을 실행 후 webpack.config.js 코드 간략한 설명
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js', //main.js 파일을 가지고와서 webpack돌려준다.
output: {
path: path.resolve(__dirname, './dist'), //webpack 하고 난 다음에 생성 위치
publicPath: '/dist/',
filename: 'build.js' //webpack 하고 난 다음에 파일 이름
},
module: {
rules: [
{
test: /\.css$/,
use: [ //오른쪽에서 왼쪽 순으로 실행 됨
'vue-style-loader',
'css-loader'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true, //한번만 해석
overlay: true //웹팩에서 오류가 났을때 웹브라이저에서 오류를 띄운다.
},
performance: {
hints: false //25kb
},
devtool: '#eval-source-map' //개발자 도구 확인용
}
if (process.env.NODE_ENV === 'production') { //NODE_ENV=production 으로 잡히면 동작 되는 분기점
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({ //정릐를 바꿔준다.
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({ //웹자원을 최대한 압축
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({ //웹자원을 최대한 압축
minimize: true
})
])
}

'webpack' 카테고리의 다른 글
| webpack 유용한 링크 모음 (0) | 2019.08.27 |
|---|---|
| webpack 자주 사용 하는 명령어 모음 (0) | 2019.08.27 |
| Webpack Dev Middleware 사용하기 (0) | 2019.08.27 |
| Webpack Dev Server Setting (0) | 2019.08.26 |
| webpack 설치 & 기본 명령어 정리 (0) | 2019.08.26 |