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来实现