Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
¿Por qué "npm run build" no genera *.asset.php cuando se trabaja con @wordpress/scripts?

Estoy construyendo bloques personalizados de gutenberg usando npm, webpack y @wordpress/scripts. Todo estuvo bien hasta que intenté usar el archivo block.json. Para usar el archivo block.json, necesito el archivo block.asset.php en el directorio de compilación porque esa es la forma en que se codifica el núcleo de WordPress... ( https://github.com/WordPress/gutenberg/issues/40447 )

Y ahora mi problema es que ejecutar npm run build no genera el archivo .asset.php y no sé por qué. Cuando registro bloques usando wp_enqueue_script o cuando creo manualmente un .asset.php vacío, funciona bien.

Mi webpack.config.js ahora se ve así:

 const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require('path');

module.exports = {
 ...defaultConfig,
 entry: {
 'cgbms-section-block': './src/section-block.js',
 'cgbms-article-block': './src/article-block.js',
 'cgbms-article-header-block': './src/article-header-block.js',
 'cgbms-category-block': './src/category-block.js',
 'cgbms-category-block-edit': './src/category-block-edit.js',
 'cgbms-card-block': './src/card-block.js',
 'style-front': './src/css/style-front.scss',
 'style-editor': './src/css/style-editor.scss',
 },
 output: {
 path: path.join(__dirname, './build/'),
 filename: './blocks/[name].js'
 },
 module: {
 ...defaultConfig.module,
 rules: [
 ...defaultConfig.module.rules,
 ]
 },
 plugins: [
 new MiniCssExtractPlugin({
 filename: './css/[name].css'
 })
 ],
 externals: { 
 '@wordpress/blocks': 'wp.blocks',
 '@wordpress/block-editor': 'wp.blockEditor' 
 },
}
almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

De acuerdo, la solución es realmente simple. Creo que tuve que importar la configuración predeterminada de los complementos: ...defaultConfig.plugins

Así que todo mi webpack.config.js es ahora:

 const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require('path');

module.exports = {
 ...defaultConfig,
 entry: {
 'cgbms-section-block': './src/section-block.js',
 'cgbms-article-block': './src/article-block.js',
 'cgbms-article-header-block': './src/article-header-block.js',
 'cgbms-category-block': './src/category-block.js',
 'cgbms-category-block-edit': './src/category-block-edit.js',
 'cgbms-card-block': './src/card-block.js',
 'style-front': './src/css/style-front.scss',
 'style-editor': './src/css/style-editor.scss',
 },
 output: {
 path: path.join(__dirname, './build/'),
 filename: './blocks/[name].js'
 },
 module: {
 ...defaultConfig.module,
 rules: [
 ...defaultConfig.module.rules,
 ]
 },
 plugins: [
 ...defaultConfig.plugins,
 new MiniCssExtractPlugin({
 filename: './css/[name].css'
 })
 ]
}

como puede ver, también eliminé el bloque externals .

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!