1、创建一个webpack项目

mkdir webpack-demo &&cd webpack-demo
npm init -y
npm install --save-dev webpack

创建一个app/index.js

function component(){
    
    ele.innerHTML = 'Hello World!';
    return ele;
}

document.body.appendChild(component());

2、配置webpack.config.js文件

var path = require('path');
var webpack = require('webpack')

module.exports = {
    
    entry: './app/index.js',
    output: {
        filename:'bundle.js',
        path:path.resolve(__dirname, 'dist')
    }
}
./node_modules/.bin/webpack --config webpack.config.js

3、使用webpack npm

配置package.json文件

"scripts": {"build":"webpack"
  },

上面可以通过使用npm run build来实现

 

posted on 2017-02-22 10:27  苏荷酒吧  阅读(316)  评论(0编辑  收藏  举报