C
C
coderlex2016-06-23 16:57:02
webpack
coderlex, 2016-06-23 16:57:02

How to pass backend variable to WebPack module on frontend?

Actually, everything is in the subject.
I had such a thought.
1. Pack AMD library:

output: {
  publicPath: '/js/',
  path: __dirname + '/web/js',

  library: 'backend',
  libraryTarget: "amd",
    
  filename: '[name].js',
  chunkFilename: 'chunk-[id].js'
}

// Where the item about the name of the library is still unclear.
2. To then from the script embedded in the page:
;(function(){
  var Entry = require('./entries/users/index');
  var entry = new Entry({
    ... // <--- тут опции, сгенерированные кодом бэкэнда (PHP)
  });
})();

As a result:
ReferenceError: require is not defined
Obviously, the require function is not included in the bundle. Where to get it? Or maybe it should be handled in some other way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Kayun, 2016-06-23
@coderlex

Write a variable to a json file, and include it in the script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question