javascript - Webpack - dynamic require and paths -


my webpack.config file looks this

var path = require('path'); var webpack = require('webpack');  module.exports = {     entry: {         app: './app'     },     output: {         path: path.resolve(__dirname, 'build'),         filename: '[name]-bundle.js'     } }; 

i have dynamic requires this

function loadmodule(modname, cb, onerr){     if (modname == 'contacts') require(['../modules/contacts/contacts', 'html!../modules/contacts/contacts.htm'], cb);     else if (modname == 'tasks') require(['../modules/tasks/tasks', 'html!../modules/tasks/tasks.htm'], cb);     else onerr(); } 

which work great. i'm seeing 1.1-bundle.js , 2.2-bundle.js getting added build folder.

the problem is, when these dynamic requires triggered, i'm seeing 404s in network tab, since webpack trying load 1-1.bundle.js root of project, instead of build folder told webpack put it.

how correct this?

you need set public path- basically, tell webpack on webserver find built files, seems the build folder.

{     output: {         path: path.resolve(__dirname, 'build'),         filename: '[name]-bundle.js',         publicpath: '/build/',     }, } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -