Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 网页:  ;;使用外部注入需求_Webpack_Vuejs2_Laravel Mix - Fatal编程技术网

Webpack 网页:  ;;使用外部注入需求

Webpack 网页:  ;;使用外部注入需求,webpack,vuejs2,laravel-mix,Webpack,Vuejs2,Laravel Mix,我使用LaravelMix和Webpack从基本框架和实例结构编译SPA (为了便于阅读,以下所有代码均缩写。) 我使用vue route generator从表中构建路由器: const routes = require('vue-route-generator') .generateRoutes({ '~', // Path to directory of page components. importPrefix: pages+'/', // String to add t

我使用LaravelMix和Webpack从基本框架和实例结构编译SPA

(为了便于阅读,以下所有代码均缩写。)

我使用
vue route generator
从表中构建路由器:

const routes = require('vue-route-generator')
.generateRoutes({
    '~', // Path to directory of page components.
    importPrefix: pages+'/', // String to add to importing component path.
    dynamicImport: true, // Use dynamic import expression (`import()`) to import component.
    nested: false, // DO NOT always treat generated route path as nested.
});
vue路由生成器
生成我期望的代码:

function Index() {
  return import(/* webpackChunkName: "index" */ '~/index.vue')
}
function People() {
  return import(/* webpackChunkName: "people" */ '~/people.vue')
}
export default [...]
我定义了一个外部接口,这样我就可以将我的路由作为
require
ment注入到框架中

mix.webpackConfig(webpack => {
    return {
        ...
        externals: [
            { routes, ... }
        ]
    };
});
注射发生在我预料之中。。。几乎。当我在devtools中检查注入的代码时,我看到:

/***/ "routes":
/*!*!*\
  !*** external "Index() {\n  return import(\n    /* webpackChunkName: \"index\" *_/ '~/index.vue'\n  )\n}\nfunction People() {\n  return import(\n    /* webpackChunkName: \"people\" *_/ '~/people.vue'\n  )\n}\n\nexport default [\n  {\n    name: 'index',\n    path: '/',\n    component: Index\n  },\n  {\n    name: 'people',\n    path: '/people',\n    component: People\n  }\n]\n" ***!
  \***/
/*! no static exports found */
/***/ (function(module, exports) {

module.exports = Index() {
  return import(/* webpackChunkName: "index" */ '~/index.vue')
}
function People() {
  return import(/* webpackChunkName: "people" */ '~/people.vue')
}
export default [...]
显然应该是这样的:

/***/ (function(module, exports) {
function Index() {
  return import(/* webpackChunkName: "index" */ '~/index.vue')
}
function People() {
  return import(/* webpackChunkName: "people" */ '~/people.vue')
}
module.exports = [...]
我需要做什么才能使Webpack正确地注入路由代码