我有一个postcss.config.js
文件:webpack2 | postcss生成警告
const webpack = require('webpack');
const path = require('path');
module.exports = {
parser: 'postcss-scss',
plugins: [
require('postcss-smart-import')({
addDependencyTo: webpack,
path: [
path.resolve(__dirname, 'src/common'),
path.resolve(__dirname, 'src/common/styles'),
path.resolve(__dirname, 'src/app1'),
path.resolve(__dirname, 'src/app2'),
]
}),
require('precss'),
require('autoprefixer'),
]
}
在
webpack.conf.js
我有一个简单的定义:
{
test: /\.(scss|sass|css)$/,
exclude: /node_modules/,
use: [
'style-loader',
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]--[hash:base64:5]',
'postcss-loader'
]
}
在构建我得到一个警告:
WARNING in ./~/css-loader?modules&importLoaders=1&localIdentName=[name]__[local]--[hash:base64:5]!./~/postcss-loader/lib!./src/common/shared/ui/Button.scss
(Emitted value instead of an instance of Error) postcss-extend: /Users/kania/projects/app-frontend/src/common/shared/ui/Button.scss:22:5: @extend is being used in an anti-pattern (extending things not yet defined). This is your first and final warning
@ ./src/common/shared/ui/Button.scss 4:14-210 13:2-17:4 14:20-216 @ ./src/common/shared/ui/Button.tsx @ ./src/common/shared/ui/index.ts (...)
在Button.scss
我有一个很简单的定义:
@import 'shared/styles/buttons';
@import 'shared/styles/fonts';
.buttonContainer {
display: flex;
}
.button {
@extend %smallFont;
padding: 0 2.5rem;
flex: 1;
&.style_primary {
@extend %buttonPrimary;
}
&.style_secondary {
@extend %buttonSecondary;
}
&.style_tertiary {
@extend %buttonTertiary;
}
}
内部.button
I类定义3个嵌套类(&.style_primary
&.style_secondary
和&.style_tertiary
)。我发现如果其中2个评论一切正常。它看起来像是如果我从一个文件中使用多个占位符选择器,它会引发警告......
占位符在导入的文件中定义,文件存在于定义的位置。
我会很感激任何提示,如何解决这个问题。
使用的包:
[email protected]^2.0.5
[email protected]^1.0.5
[email protected]^0.7.4
[email protected]^1.4.0 [email protected]^7.1.1
[email protected]^2.5.1
[email protected]^2.4.5
我使用这个命令来运行构建: webpack-dev-server --hot --progress --config webpack.dev.config.js
你的CSS编译是否正确?你想解决什么问题? –
我想删除一个警告,因为这个文件的样式不适当地构建 – Kania