Andreas Köberle
Andreas Köberle

Reputation: 111042

How to replace requireJS config in webpack es6 project

I want to refactor a large requireJS project to use es6 import/export and webpack. In the requireJS requirejs.config call, I use the config section to pass some project specific settings to some views:

requirejs.config({
  baseUrl: 'js/cfe/app',
  paths: { },
  config: {
    'views/test/TestView': {
      isTest: true
    }
})

and in the view:

define(['module'], function(module) {
  var t = module.config().isTest
})

How can I accomplish the same behaviour in my webpack setup?

Upvotes: 0

Views: 410

Answers (1)

KisaneNeko
KisaneNeko

Reputation: 96

I'm not quite sure if I understand your question correctly, but maybe you can use my answer anyways.

I think you could extract your configuration object to JSON file, use a loader (RAW loader works fine) to include it in your bundle, and then when you need it simply use ES6 import:

import config from 'myconfig.json';

Upvotes: 1

Related Questions