N
N
Ninja Mate2016-03-17 14:07:18
JavaScript
Ninja Mate, 2016-03-17 14:07:18

How to set a dynamic path to a file during assembly?

There is a problem with the production assembly of js files (from react).
The task is to set the path to the script dynamically and set up the development environment for further work.

//Так все собирается в один файл
import { Users } from './Admin/Users';
//А так собирает в разные файлы
require.ensure([], function(require) { var Users = require('./Admin/Users'); }, 'users');
//При сборке require.ensure возникает проблема использовать элемент Users
//Как можно использовать его здесь? 
<Route  path="Users" component={Users}></Route>

//Скрипры на thml для разработки подключаю, но users.bundle не видит
  <script src="static/bundle.js"></script>
  <script src="static/users.bundle.js"></script>

config is like this
output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
    publicPath: '/static/', // здесь нужен аналог php функции include (dirname(__FILE__)."/../Users.js");
    chunkFilename: '[name].bundle.js'
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikita Gushchin, 2016-03-17
@victorzadorozhnyy

react-router supports this functionality out of the box - documentation and sample application

D
Dmitry Belyaev, 2016-03-17
@bingo347

Move the Users declaration up a level in the closure

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question