【问题标题】:how to require webpack bundles in js files如何在 js 文件中要求 webpack 包
【发布时间】:2017-01-21 03:38:35
【问题描述】:

我想在一个也被捆绑的 app.js 中需要来自 webpack 的两个捆绑文件。我的文件夹如下所示:

MyApp
|-app
|   -app.js  <-this gets bundled
|-hero
|  -hero.module  <- this gets also bundled
|  -some other stuff that will be bundled in hero.bundle.js
|-crisis
|  -crisis.module <- gets bundled
|  -more stuff that gets bundled in crisis.bundle.js
-

到目前为止一切顺利。 我想在 app.js 中需要 hero.bundle.js 和 risk.bundle.js,因为我在 app.js 中使用我的组件路由器延迟加载/路由。 但是我经常收到错误,找不到模块。 要求之一的示例语法:

path: '/heroes/...',
            name: 'Heroes',
            loader: function () {
                // lazy load Heroes
                return $ocLazyLoad.load([require('./dist/heroes.bundle.js')])
                    .then(function () {
                        return 'heroes';
                    });
            }

我做错了吗?

提前谢谢:)

【问题讨论】:

  • 我实际上在 webpack.config.js 中创建了带有入口和输出的包,而不是 CommonsChunk。唯一的问题是如何将我的 bundle.js 文件包含到 javascript 文件中,而不是 html

标签: angularjs webpack bundle router


【解决方案1】:

我得到了解决方案: Webpack 没有找到我的文件。搜索到的路径

C:/someFolders/heroApp/app/dist/heroes.bundle.js

尽管如此

C:/someFolders/heroApp/dist/heroes.bundles.js

设置两个点是解决方案:

require('../dist/heroes.bundle.js')

【讨论】:

    猜你喜欢
    • 2019-05-13
    • 2017-04-10
    • 2018-08-01
    • 2020-10-16
    • 2017-06-04
    • 1970-01-01
    • 2021-07-03
    • 2017-06-14
    • 2022-01-01
    相关资源
    最近更新 更多