内容简介:创建入口文件 app.js执行 Webpack 命令打包 webpack <entry> [<entry>] <output>(呃呃呃额额
创建入口文件 app.js
// es6 module 规范
import sum_d from './sum.js'
import {sum_e} from './sum.js'
// commcon js 规范
var minus = require('./minus.js')
console.log('sum_d(4,6)= ', sum_d(4,6))
console.log('sum_e(9,3)= ', sum_e(9,3))
console.log('minus(8,2)= ', minus(8,2))
方法一: es6 module 规范
/* sum.js */
export default function (a, b) {
return a + b
}
// import 导入时要加 {name} name为 export name
export function sum_e (a, b) {
return a + b
}
方法二:commcon js 规范
/* minus.js */
module.exports = function(a, b) {
return a -b
}
执行 Webpack 命令打包 webpack <entry> [<entry>] <output>( webpack 4+ 后不支持了 )
webpack app.js bundle.js
呃呃呃额额
打包 ERROR in Entry module not found: Error: Can't resolve 'app.js' in The 'mode' option has not been set ,错误提示
查了一下官方文档才得知,webpack的打包cli命令已经更改:
webpack <entry> [<entry>] -o <output>
webpack app.js -o bundle.js
打包成功,得到了 bundle.js啦
使用 node 执行 bundle.js
以上所述就是小编给大家介绍的《Webpack 一,打包JS》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- 【前端打包部署】谈一谈我在SPA项目打包=>部署的处理
- Maven多模块项目打包前的一些注意事项(打包失败)
- tar打包如何不打包某一个文件夹(排除某些文件夹)
- iOS新手用swift写一个macos打包工具 一键打包到指定位置
- Android应用签名打包
- 多渠道打包
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
We Are the Nerds
Christine Lagorio-Chafkin / Hachette Books / 2018-10-2 / USD 18.30
Reddit hails itself as "the front page of the Internet." It's the third most-visited website in the United States--and yet, millions of Americans have no idea what it is. We Are the Nerds is an eng......一起来看看 《We Are the Nerds》 这本书的介绍吧!