开始使用 webpack 4 的问题 [英] Issues with getting started with webpack 4

查看:58
本文介绍了开始使用 webpack 4 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全按照此处的说明来学习教程.但令我惊讶的是,这些文档似乎已经过时了.例如

I am following the tutorial exactly as given here . But I am amazed that the docs seems outdated. e.g

npx webpack src/index.js dist/bundle.js 失败:

CLI 移动到一个单独的包中:webpack-cli.请安装'webpack-cli' 除了 webpack 本身使用 CLI.-> 使用 npm 时: npm install webpack-cli -D-> 使用 yarn 时: yarn add webpack-cli -D

The CLI moved into a separate package: webpack-cli. Please install 'webpack-cli' in addition to webpack itself to use the CLI. -> When using npm: npm install webpack-cli -D -> When using yarn: yarn add webpack-cli -D

如果我安装 webpack-cli 并重试,我会看到此错误:

If I install webpack-cli and try again I see this error:

哈希:af9bc06fd641eb0ffd1e 版本:webpack 4.0.0 时间:3865ms 内置at: 2018-2-26 05:10:45 1 资产入口点 main = main.js 1(webpack)/buildin/module.js 519 字节 {0} [内置] 2(webpack)/buildin/global.js 509 字节 {0} [内置] [3]./src/index.js 212 字节 {0} [内置] [4] 多 ./src/index.jsdist/bundle.js 40 字节 {0} [内置]+ 1 个隐藏模块

Hash: af9bc06fd641eb0ffd1e Version: webpack 4.0.0 Time: 3865ms Built at: 2018-2-26 05:10:45 1 asset Entrypoint main = main.js 1 (webpack)/buildin/module.js 519 bytes {0} [built] 2 (webpack)/buildin/global.js 509 bytes {0} [built] [3] ./src/index.js 212 bytes {0} [built] [4] multi ./src/index.js dist/bundle.js 40 bytes {0} [built] + 1 hidden module

配置中的警告 'mode' 选项尚未设置.放'mode' 选项到 'development' 或 'production' 以启用默认值这种环境.

WARNING in configuration The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment.

多 ./src/index.js dist/bundle.js 模块中的错误未找到:错误:无法解析/var/app/webpack_demo"@multi 中的dist/bundle.js"./src/index.js dist/bundle.js

ERROR in multi ./src/index.js dist/bundle.js Module not found: Error: Can't resolve 'dist/bundle.js' in '/var/app/webpack_demo' @ multi ./src/index.js dist/bundle.js

我希望我没有做一些疯狂的事情,鉴于 webpack 的流行,文档应该反映实际行为.如果我是,请告诉我做错事了.

I hope I am not doing something crazy, given the popularity of webpack the documentation should reflect the actual behavior. Let me know if I am doing something wrong.

升级到webpack 4的详细说明,可能会有帮助

A details description of upgrade to webpack 4,that might be helpful

推荐答案

您可以在 webpack config 或 cli 命令中传递 mode 参数.

You can pass mode param in the webpack config or cli command.

配置:mode: 'development'mode: 'production'

CLI:webpack --mode developmentwebpack --mode production

这篇关于开始使用 webpack 4 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆