webpack配置基础

栏目: 编程语言 · 发布时间: 6年前

内容简介:最新版本的webpack已经可以不需要webpack.config.js作为配置文件。如果你的项目缺失配置文件的话,webpack会做以下默认配置:如果项目根目录有webpack.config.js文件,那webpack会默认使用它作为配置文件。我们也可以自己在命令行里通过 --config 指定配置文件,例如:webpakc使用node.js内置的path库来处理路径:

1: 默认entry和output

最新版本的webpack已经可以不需要webpack.config.js作为配置文件。如果你的项目缺失配置文件的话,webpack会做以下默认配置:

entry - src/index.js
output - dist/main.js

2: 默认配置文件 vs 制定配置文件

如果项目根目录有webpack.config.js文件,那webpack会默认使用它作为配置文件。我们也可以自己在命令行里通过 --config 指定配置文件,例如:

"scripts": {
  "build": "webpack --config prod.config.js"
}

3: path

webpakc使用node.js内置的path库来处理路径:

const path = require('path')

你可能还会注意到这个变量:__dirname

__dirname 的值就是当前module的路径,它和对__filename执行path.dirname()是一样的。例如:在/Users/mjr 路径下执行node example.js,那么:

console.log(__dirname);
// Prints: /Users/mjr
console.log(path.dirname(__filename));
// Prints: /Users/mjr

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

查看所有标签

猜你喜欢:

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

Algorithms in C (Computer Science Series)

Algorithms in C (Computer Science Series)

Robert Sedgewick / Addison-Wesley Professional / 1990-01-11 / USD 59.99

This new version of the best-selling book, Algorithms, SecondEdition, provides a comprehensive collection of algorithmsimplemented in C. A variety of algorithms are described in eachofthe following ar......一起来看看 《Algorithms in C (Computer Science Series)》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具