[英]Bug with css-loader / style-loader
我在两台不同的 PC 上遇到了一个问题。 对于我的项目,我为开发安装了以下依赖项:(webpack webpack-cli @babel/core @babel/preset-env @babel/preset-react babel-loader css-loader style-loader html-webpack-plugin) 和反应和反应-dom。 当我尝试在项目的任何组件中导入一些样式表时,问题就来了,错误是: import api from ".../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag;js"; . 我有点困惑,因为我检查了很多次自己完成的其他 webpack 配置,它们与我现在使用的相同。 你有什么建议? 谢谢!
我有这个问题,似乎 webpack 不允许 styles css 文件的多个定义。 因此,为我解决问题的方法是从 angular.json 中的“样式”中删除 css 文件
//....
"architect": {
"build": {
"builder": "@angular-builders/custom-webpack:browser",
"options": {
"outputPath": "dist/app-name",
"index": "src/index.html",
"main": "src/app/main.ts",
"polyfills": "src/app/polyfills.ts",
"tsConfig": "tsconfig.json",
"preserveSymlinks": true,
"assets": [
"src/client/img"
],
"styles": [], //don't mention your styles.css here
"scripts": [],
//....
webpack.config.js 应该包括加载程序,它应该足够了
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.