还不能调用 Encore.setOutputPath(),因为运行时环境似乎没有配置

Jul*_*eno 3 phpstorm webstorm reactjs webpack

我正在设置 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();
Run Code Online (Sandbox Code Playgroud)

Jek*_*kis 9

它失败是因为 Encore 运行时环境仅在您运行时配置(例如,在执行时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
Run Code Online (Sandbox Code Playgroud)