ASH84

Software Engineer/Developer, co-founder of Payhere. Ex-Banksalad. Intereseted in iteroperability, bootstrap company, writting.

모듈화 Webpack 관련 정리

created:2016-04-12
updated:2016-04-25
edit

주의 - 본 글은 타링크에 대한 개인적인 정리글입니다.

webpack

webpack --watch - 코드를 수정시, 자동으로 컴파일 수행

webpack.config.js

module.exports = {

  entry: './entry.js',
  output: {
    path : __dirname,
    filename: 'bundle.js'
  },
  module :{

  }, 
  devtool: '#inline-source-map'
}
var $ = require("jquery");  
var hello = require("./hello");  
var world = require("./world");

$("#test").text(hello + ', ' + world);
$cat hello.js world.js
module.exports = 'Hello';  
module.exports = 'world';  
<div id="test"></div>  
<script type="text/javascript" src="bundle.js"></script>  

webpack 을 통해서 entry.js 와 모듈로 사용하고 있는 hello.js, world.js 가 하나의 bundle.js 로 만들어진다. 사용해보면 그렇게 어렵지 않다는 것을 느끼게 되긴 하는데, 자바스크립트 진영에서 진짜 활발하게 움직이고 있다는 생각이 들었다. 확실히 require, exports는 익숙하지는 않지만, 모듈별로 로그해서 사용할 수 있다는 부분은 재밌는것 같다.

Reference


#JS  #webpack  #commonJS