reactjs - 还不能调用 Encore.setOutputPath(),因为运行时环境似乎没有配置
问题描述
我正在设置 webpack.config.js 但我错过了该setOutputPath()
函数发出的警告 PhpStorm 消息
我有 PhpStorm 的 2018.3.2 版本,我在 Linux Debian 中工作
let Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './assets/js/app.js')
.splitEntryChunks()
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
.enableReactPreset()
.configureBabel(function (babelConfig) {
babelConfig.presets.push('@babel/preset-flow');
babelConfig.plugins.push("@babel/plugin-proposal-class-properties");
babelConfig.plugins.push('styled-jsx/babel');
});
module.exports = Encore.getWebpackConfig();
解决方案
它失败是因为 Encore Runtime Environment 仅在您运行时配置(例如,在执行时
yarn encore dev
)。修复此问题调用Encore.isRuntimeEnvironmentConfigured()
和Encore.configureRuntimeEnvironment()
方法:
// webpack.config.js
const Encore = require('@symfony/webpack-encore')
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
}
// ... the rest of the Encore configuration
推荐阅读
- exe - 执行 exe 文件时出错。“原因:系统找不到指定的文件”
- android - 我得到“调用需要 API 级别 X(当前最小值为 Y)”,即使我将 min 更改为 X
- web-scraping - 是否可以将 Scrapy 实现到桌面应用程序中?
- django - Heroku 在通过 Django 部署之前构建 React 应用程序
- android - 在 MaterialCardView 的中心设置自定义图标
- elasticsearch - 按日期和对象分组弹性搜索
- eslint - eslint 中的 Tslint 规则等效
- swift - 覆盖变量中的值
- scala - 如何根据 Scala 中的对象字段对 List 对象进行排序?
- javascript - 当我使用多个 jQuery change() 方法调用它时,如何避免多次调用我的函数?