Answer the question
In order to leave comments, you need to log in
How to set a name for a chunk using require.ensure?
The application is divided into chunks using require.ensure and the whole process is driven by the react router.
The folder with the index to which the request is made
module.exports = function(location, cb) {
if (typeof require.ensure == 'function') {
/* Asynchronous loading of a component
that is inside of require.ensure */
require.ensure([], (require) => {
cb(null, require('./Reports'), 'reports')
})
} else {
/* Server side synchronous loading */
cb(null, require('./Reports'), 'reports');
}
}
<Route path="Reports" getComponent={
(location,cb)=>require('./Reports/index')(location,cb)
}> </Route>
output: {
path: path.join(__dirna
filename: 'bundle.js',
chunkFilename: '[name].bundle.js' //в моем случае имя выглядит 1.bundle.js
},
//если задавать так, то все идет по плану и файл получается reports.bundle.js
//как сделать эту магию в моем случае?
componentDidMount(){
var Reports;
require.ensure([], function(require) {
Reports = require('./Reports').default;
render(<Reports/>, document.getElementById('fl'));
}, 'reports');
}
Answer the question
In order to leave comments, you need to log in
The chunk name is given in the third parameter of require.ensure . Try like this:
module.exports = function(location, cb) {
if (typeof require.ensure == 'function') {
require.ensure([], (require) => {
cb(null, require('./Reports'))
}, 'reports'); // третий параметр
} else {
cb(null, require('./Reports'));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question