首页 > 解决方案 > 还不能调用 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();

标签: reactjswebpackphpstormwebstorm

解决方案


它失败是因为 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

推荐阅读