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配置基础》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

The Smashing Book

The Smashing Book

Jacob Gube、Dmitry Fadeev、Chris Spooner、Darius A Monsef IV、Alessandro Cattaneo、Steven Snell、David Leggett、Andrew Maier、Kayla Knight、Yves Peters、René Schmidt、Smashing Magazine editorial team、Vitaly Friedman、Sven Lennartz / 2009 / $ 29.90 / € 23.90

The Smashing Book is a printed book about best practices in modern Web design. The book shares technical tips and best practices on coding, usability and optimization and explores how to create succes......一起来看看 《The Smashing Book》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

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

RGB CMYK 互转工具

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

HEX HSV 互换工具