第一个webpack应用

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="app"></div>
    <script src="./dist/bundle.js"></script>
</body>
</html>

依赖show.js模块

function show (content) {
    document.getElementById('app').innerText = 'hello ' + content
}
module.exports = show

入口文件main.js

const show = require('./show')
show('webpack')

webpack配置文件webpack.config.js

const path = require('path')
module.exports = {
    entry: './main.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, './dist')
    }
}

运行webpack 自动打包成bundle.js 打开页面 输出 hello webpack

猜你喜欢

转载自blog.csdn.net/qq867263657/article/details/89132934
今日推荐