2

Need help understanding "Provide your own webpack config" https://developer.wordpress.org/block-editor/packages/packages-scripts/#provide-your-own-webpack-config

const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

module.exports = {
    ...defaultConfig,
    entry: {
        ...defaultConfig.entry,
        //index: path.resolve( process.cwd(), 'src', 'index.js' ),
        slider: path.resolve( process.cwd(), 'src', 'slider.js' ),

    },
};

I am trying here to add a new scipt to the buid folder from src folder while developing a gutenberg block I get error:

ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `wp-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

Same for Adding other distinct css file how can I do it?

7
  • If you remove the slider: ... part, does it work? Does the full log (from the file) have more details on what is actually going wrong?
    – kero
    Jan 28, 2021 at 11:05
  • Yes it is working Jan 28, 2021 at 11:06
  • Ok, I haven't worked with Webpack in some time, but do you even need a new entry? And are you sure ./src/slider.js exists and has code in it that doesn't produce errors?
    – kero
    Jan 28, 2021 at 11:09
  • No I dont think I have an error in the src/slider.js: console.log('im here too') import $ from jquery window.jQuery = window.$ = $; jQuery(document).ready(function( $ ) { $('.carousel').slick({ rtl: true }); }); ... npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] start: wp-scripts start npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: Jan 28, 2021 at 11:16
  • Are you trying to have multiple scripts that each get transpiled to their own bundle, with their own map, and their own asset PHP file? AKA having 2 projects but using a single command and webpack not 2?
    – Tom J Nowell
    Jan 28, 2021 at 11:16

1 Answer 1

0

Thank you all for your help! I was on it since days!

I found my problem:

https://webpack.js.org/concepts/entry-points/ helped me to find the solution

Apparently path.resolve( process.cwd(), 'src', 'slider.js' ) was not working: replacing by simple string path fixed the problem:

const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );

module.exports = {
    ...defaultConfig,
    entry: {
        ...defaultConfig.entry,
        slider: './src/slider.js',
    },
};
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.