Webpack Basic - ChoDragon9/posts GitHub Wiki
Install
$ mkdir hello-webpack
$ cd hello-webpack
$ npm init
$ npm i webpack webpack-cli -D
Getting start
webpack.config.js
const path = require('path')
module.exports = {
entry: './entry.js',
output: {
path: path.resolve(__dirname,'dist'),
filename: 'bundle.js'
}
}
์ํ ์ฝ๋ ๋ง๋ค๊ธฐ
entry.js
import { foo } from './foo'
import { bar } from './bar'
foo()
bar()
bar.js
export const bar = {
bar () {
console.log("bar")
}
}
foo.js
export const foo = {
foo () {
console.log("foo")
}
}
build
build
๋ช
๋ น์ด ์ถ๊ฐ
package.json ์ "scripts": {
"build": "webpack --config webpack.config.js"
}
webpack build
$ npm run build
โโโ dist
โโโ bundle.js
Webpack Nodejs
webpack์์ nodejs ์ฝ๋๋ฅผ ๋น๋ํ๋ ค๋ฉด target๋ฅผ ์ง์ ํด์ค์ผ ํ๋ค.
module.exports = {
entry: './entry-server.js',
target: 'node'
}