我只想在我的项目中使用 MDL 的布局组件。
所以,在我的app.css
文件中,我正在导入这个:
@import url('~material-design-lite/src/layout/_layout.scss');
在构建过程中,我收到以下错误:
ERROR in ./~/css-loader!./~/material-design-lite/src/layout/_layout.scss
Module not found: Error: Cannot resolve 'file' or 'directory' ../variables in /Users/Mitch/Documents/project/web/node_modules/material-design-lite/src/layout
@ ./~/css-loader!./~/material-design-lite/src/layout/_layout.scss 3:10-66
ERROR in ./~/css-loader!./~/material-design-lite/src/layout/_layout.scss
Module not found: Error: Cannot resolve 'file' or 'directory' ../mixins in /Users/Mitch/Documents/project/web/node_modules/material-design-lite/src/layout
@ ./~/css-loader!./~/material-design-lite/src/layout/_layout.scss 4:10-63
_layout.sccs
从这些行开始
@import "../variables";
@import "../mixins";
有什么想法我可能做错了吗?
我的相关部分webpack.config.js
:
const PATHS = {
node_modules: path.resolve(__dirname, 'node_modules'),
build: path.join(__dirname, 'public', 'build'),
js: path.resolve(__dirname, 'public', 'js'),
css: path.resolve(__dirname, 'public', 'css'),
};
...
resolve: {
root: [
path.resolve(__dirname),
PATHS.node_modules,
PATHS.js,
PATHS.css
],
...
extensions: ['', '.js', '.jsx', '.json', '.css', '.scss']
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css?modules!sass')
},
{
test: /\.png$/,
loader: 'url-loader?limit=100000'
},
{
test: /\.jpg$/,
loader: 'file-loader'
},
{
test: /\.gif$/,
loader: 'file-loader'
},
{
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&mimetype=application/font-woff'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&mimetype=application/octet-stream'
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file'
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url?limit=10000&mimetype=image/svg+xml'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}
]
}
...
相关依赖:
...
"devDependencies": {
"babel-core": "^6.14.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.14.0",
"css-loader": "^0.25.0",
"eslint": "^3.6.1",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.9.0",
"node-sass": "^3.10.1",
"sass-loader": "^4.0.2",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"webpack": "^1.13.2",
"webpack-validator": "^2.2.7"
}
...
更新
我尝试了@import url('~material-design-lite/src/material-design-lite.scss');
,因为这不是部分的,所以在我修改为只导入布局组件之后。
现在我收到以下错误:
ERROR in ./~/css-loader!./~/material-design-lite/src/material-design-lite.scss
Module build failed: Unknown word (19:1)
17 | /* Material Design Lite */
18 |
> 19 | // Variables and mixins
| ^
20 | @import "variables";
21 | @import "mixins";
22 |
@ ./~/css-loader!./public/css/app.css 3:10-114
它在评论上失败了。我不知道如何解决这个问题,我尝试使用postcss
andpostcss-scss
加载器和postcss-strip-inline-comments
插件无济于事;旧的错误只是被新的错误所取代。