4

I use the current version of react-boilerplate (which uses webpack) and installed Semantic-UI-React like described in the official docs http://react.semantic-ui.com/usage

When I start the server I get:

Server started ! ✓

Access URLs:
-----------------------------------
Localhost: http://localhost:3000
      LAN: http://192.168.100.103:3000
-----------------------------------
Press CTRL-C to stop

webpack built dba595efb772df0727e8 in 11657ms

ERROR in ./semantic/dist/semantic.min.css
Module parse failed: /Users/standardnerd/development/template/semantic/dist/semantic.min.css Unexpected character '@' (11:0)
You may need an appropriate loader to handle this file type.
|  *
|  */
| @import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic&subset=latin);/*!
|  * # Semantic UI 2.2.7 - Reset
|  * http://github.com/semantic-org/semantic-ui/
 @ ./app/app.js 20:0-43
 @ multi main

What kind of 'appropriate loader' do I need?

The parser doesn't like the @import statement in /semantic/dist/semantic.min.css:

@import url(https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic&subset=latin);

How to resolve this issue?

4

3 回答 3

5

如果您在规则中使用包含指令,请确保还包含 node_modules:

{
  test: /\.css$/,
  use: ['style-loader', 'css-loader', 'resolve-url-loader'],
  include: [
    path.join(__dirname, 'src'),
    /node_modules/
  ],
},

这应该可以解决问题,因为它指示 webpack 在加载 css 时确保包含节点模块,以便在导入语义 ui css 包时它可以正确利用 css-loader。

于 2017-05-02T14:12:46.893 回答
3

Step1:安装以下软件包

npm install --save-dev css-loader sass-loader node-sass url-loader file-loader

Step2:然后,在 webpack.config.js 文件中:

module: {
    rules: [
        {
            test: /\.css$/,
            loader: 'style-loader!css-loader'
        },
        {
            test: /\.s[a|c]ss$/,
            loader: 'sass-loader!style-loader!css-loader'
        },
        {
            test: /\.(jpg|png|gif|jpeg|woff|woff2|eot|ttf|svg)$/,
            loader: 'url-loader?limit=100000'
        }
    ]
}

Step3:在模块中,

如果你通过 npm package 安装了语义 css npm install --save-dev semantic-ui-css,那么 import 条目应该是import './node_modules/semantic-ui-css/semantic.min.css'

如果您尚未semantic-ui-css通过 npm 安装,请使用相关导入语句。

于 2018-01-18T09:14:33.587 回答
0

我可以通过安装 sass-loader 来解决这个问题——因为无论如何我都会使用 scss。

npm install sass-loader node-sass webpack --save-dev

./semantic/dist/semantic.min.css重命名./semantic/dist/semantic.min.scss 并修改配置:

    test: /\.scss$/,
      use: [{
        loader: 'style-loader',
      }, {
        loader: 'css-loader',
      }, {
        loader: 'sass-loader',
      }],
于 2017-02-17T10:02:24.183 回答