简体   繁体   English

使用Webpack导入CSS库

[英]Import css library with webpack

I'm building a project with Vue.js and I'm using the webpack template to start. 我正在使用Vue.js构建一个项目,并且正在使用webpack模板开始。 In the documentation [ http://vuejs-templates.github.io/webpack/pre-processors.html] I can read this: 在文档[ http://vuejs-templates.github.io/webpack/pre-processors.html]中,我可以阅读以下内容:

Standalone CSS Files 独立的CSS文件

To ensure consistent extraction and processing, it is recommended to import global, standalone style files from your root App.vue component, for example: 为了确保一致的提取和处理,建议从根App.vue组件导入全局独立样式文件,例如:

 <!-- App.vue --> <style src="./styles/global.less" lang="less"></style> 

Note you should probably only do this for the styles written by yourself for your application. 请注意,您可能只应该对自己为应用程序编写的样式执行此操作。 For existing libraries eg Bootstrap or Semantic UI, you can place them inside /static and reference them directly in index.html. 对于现有的库,例如Bootstrap或Semantic UI,您可以将它们放在/ static中,并直接在index.html中引用它们。 This avoids extra build time and also is better for browser caching. 这样可以避免额外的构建时间,并且更适合浏览器缓存。

So the workflow to include a css library (like Normalize or Bootstrap) is to install it through npm/yarn, copy it to /static and then refer to it in the index.html file? 因此,包括css库(如Normalize或Bootstrap)的工作流程是通过npm / yarn安装它,将其复制到/ static,然后在index.html文件中引用它? Because I find this method very tedious and fragile, what if I want to upgrade the package? 因为我发现此方法非常繁琐且脆弱,所以如果我要升级软件包怎么办? I will need to copy them again in the /static folder... 我将需要再次将它们复制到/ static文件夹中...

There is no other way to include css library installed through package manager with webpack? 还有没有其他方法可以将通过程序包管理器安装的CSS库与webpack包括在一起?

Basically, you can use css-loader plugin for Webpack. 基本上,您可以将css-loader插件用于Webpack。 Simply edit your webpack.config.js and import css by doing this: 只需编辑您的webpack.config.js并通过执行以下操作导入css:

import css from 'file.css'; 从'file.css'导入CSS;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM