我如何配置Webpack以与Symfony 4项目一起使用

问题描述 投票:-1回答:1

我刚刚通过命令npm install --save @ babel / preset-env安装了Babel,安装后,我在根目录下创建了一个“ .babelrc”文件,并进行了以下配置:{"presets": ["@ babel / preset-env"]}

尽管出现以下错误:

警告将不使用configureBabel()的“ callback”参数,因为您的应用程序已经提供了外部Babel配置(“ package.json中的” .babelrc“文件,”。babelrc.js“文件或” babel“键”)。使用null作为第一个参数可删除该警告。弃用configureBabel:不建议使用“ include_node_modules”。请改为使用“ includeNodeModules”。错误:调用configureBabel()时,不能同时使用“ includeNodeModules”和“ exclude”选项。

symfony4 babel
1个回答
0
投票

在我的情况下,我有相同的错误,并且我使用此配置解决了(抱歉,我的英语不好):在文件中:webpack.config.js

var Encore = require('@symfony/webpack-encore');

Encore
// Directorio donde se almacenarán los assets ya compilados.
.setOutputPath('public/build/')

.setPublicPath('/build')

// Nuestro archivo app.js, que será compilado y almacenado en /web/build/app.js
.addEntry('app', './assets/js/app.js')
// .addEntry('buscarRepuesto', './assets/js/Components/buscar repuesto/buscarRepuesto.js')

// Habilitar el mapeo de recursos en Desarrollo.
.enableSourceMaps(!Encore.isProduction())

// Borra el contenido del directorio /web/build antes de volver a compilar una nueva versión.
.cleanupOutputBeforeBuild()

// Muestra una notificación cuando se ha finalizado la compilación.
.enableBuildNotifications()

// Activa React
.enableReactPreset()
;

// Exporta la configuración final
module.exports = Encore.getWebpackConfig();

在我的文件。babelrc

{
"presets": [
   "@babel/preset-env",
   "@babel/preset-react"
],
"plugins": [
    [ 
      "@babel/plugin-proposal-class-properties"
    ]
 ]
 }

我的packages.json是:

{
"devDependencies": {
  "@babel/plugin-proposal-class-properties": "^7.8.3",
  "@babel/preset-env": "^7.9.5",
  "@babel/preset-react": "^7.9.4",
  "@symfony/webpack-encore": "^0.29.1",
  "babel-preset-react": "^6.24.1",
  "bootstrap": "^4.4.1",
  "prop-types": "^15.7.2",
  "react": "^16.13.1",
  "react-dom": "^16.13.1",
  "webpack-notifier": "^1.8.0"
},
"dependencies": {
  "node-sass": "^4.14.0",
  "react-router-dom": "^5.1.2"
}
}
© www.soinside.com 2019 - 2024. All rights reserved.