Webpack 一,打包JS

栏目: IT技术 · 发布时间: 5年前

内容简介:创建入口文件 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


以上所述就是小编给大家介绍的《Webpack 一,打包JS》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

We Are the Nerds

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》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

在线进制转换器
在线进制转换器

各进制数互转换器

html转js在线工具
html转js在线工具

html转js在线工具