问题标签 [imports-loader]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
195 浏览

webpack - Can I use webpack imports-loader to require CSS files alongside certain JS dependencies? (or, how to implicitly load CSS)

I'm trying to convert a large project using RequireJS to Webpack 4. The end goal is to be able to use both tools side by side, at least for development, with minimal changes to actual code required.

I'm running into an issue with converting shim entries in my RequireJS config file to their Webpack equivalents when CSS is involved. For example, here's what a RequireJS config entry looks like:

The Webpack recommended way to shim is by using imports-loader, so here's what I've tried there (inside module.rules array):

The JS seems to resolve fine. I can't get the CSS to load this way. Other CSS files that are explicitly imported alongside the dependencies themselves load fine.

I guess I can create a wrapper file that requires CSS and the original dependency explicitly side by side. It would be a bit of a pain but not too much work. We do have a lot of these entries in our RequireJS config.

However... is there really no way to shim / load CSS implicitly like this with Webpack? Is imports-loader the wrong tool for the job here? I feel like I must be missing something.

Thanks!

0 投票
1 回答
209 浏览

meteor - Meteor Wonky Magic 进口

我已经使用流星一段时间了,并且遇到了意外的行为,我的文件系统设置如下:

在 shared.js 中,我创建了我的 mongo 集合:

Collection= new Mongo.Collection('collection');

然后我可以在我的应用程序的任何地方将它们作为全局变量引用。有趣的是:我从来没有在我的项目中使用过“共享”这个词,意思是,我从来没有导入这个文件,我从来没有需要这个文件,它是自己加载的,并且在没有被告知的情况下工作。

我目前正在尝试将其复制到另一个项目中,但无济于事。谁能解释为什么它在一个项目中加载,而不是另一个?以及如何在我的第二个项目中获得这种行为?

在查看之后,似乎在我的第二个项目中,shared.js 根本没有加载。

0 投票
0 回答
359 浏览

webpack - 如何将内联导入加载器转换为配置导入加载器?

我正在尝试为旧版 SPA 引入 webpack。我与本文的作者处于非常相似的位置我已将他们的代码改编为 webpack v4。

该应用程序需要全局定义 myApp ,所以我公开myApp如下:

应用程序.js

webpack.config.js

通过添加一些额外的代码,这可以完美地递归地“注入”该全局变量:

entryPoint.js

这不起作用在以下定义它webpack.config.js

webpack.config.js

在检查包时,webpack 没有additionalCode 像使用内联导入加载器时那样添加。

任何指向配置翻译出错的指针?

编辑 2020 年 10 月 8 日

这是我的应用程序的结构:

角度控制器期望 myApp 像这样定义,例如:

登陆.js

0 投票
1 回答
154 浏览

jquery - 如何在导入加载器配置的测试中添加模块

当我将旧版 webapp 转换为基于 webpack 的应用程序时,它使用mCustomScrollbar。根据 mCustomScrollbar 的文档,使用 webpack 运行需要使用 imports-loader。但是 doc 中给出的语法与旧版本的 webpack 兼容,而不是与最新版本兼容。

根据imports-loader的文档,我无法添加malihu-custom-scrollbar-plugintest.modules-rules

给出以下错误,

我的 vendor.js 如下所示,

那么如何让它工作以及如何在同一个导入加载器中组合两个模块,在我的例子中jquery-mousewheelmalihu-custom-scrollbar-plugin.

0 投票
0 回答
13 浏览

webpack - 在 webpack 中更新旧的 imports-loader 定义

我的任务是将大量遗留的 webpack 配置从 webpack 2 更新到 webpack 4。

有些部分工作正常。

有些不是那么多:)

棘手的部分之一是旧版本加载器的许多文档都不是很好,并且它们的界面随着时间的推移发生了巨大的变化,因此为了推动它向前发展而弄清楚之前发生的事情是令人沮丧的。

一个例子:

这是我拥有的导入加载程序定义(imports-loader v0.70):

我不知道如何将其转换为 v1.2 语法,因为我找不到任何类似于我们之前的示例。现在我有这个(但不知道这是否正确):