Ask A Question

Notifications

You’re not receiving notifications from this thread.

how to properly configure webpack for production

Sourabh Soni asked in Rails

root@ubuntu:~/Make-Rails# ./bin/webpack
[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.

  • configuration.node should be one of these: false | object { __dirname?, __filename?, global? } -> Include polyfills or mocks for various node stuff. Details:
    • configuration.node has an unknown property 'dgram'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features.
    • configuration.node has an unknown property 'fs'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features.
    • configuration.node has an unknown property 'net'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features.
    • configuration.node has an unknown property 'tls'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features.
    • configuration.node has an unknown property 'child_process'. These properties are valid: object { __dirname?, __filename?, global? } -> Options object for node compatibility features.

// environment.js
const { environment } = require('@rails/webpacker');

// Correct way to set custom entry points
// This assumes you have an entry point at './app/javascript/packs/application.js'
// Adjust the path according to your project structure
environment.config.set('entry', {
application: ['./app/javascript/packs/application.js']
});

module.exports = environment;

//config/webpack/production.js
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
const environment = require('./environment')
module.exports = environment.toWebpackConfig()

{
"dependencies": {
"@rails/webpacker": "5.4.4",
"webpack": "5.0.0",
"webpack-cli": "4.0.0",
"bootstrap": "5.1.3"
},
"devDependencies": {
"webpack-dev-server": "4.0.0"
},
"license": "MIT"
}

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.