0

我正在尝试开始使用 webpack 和 Grommet 一起工作。我正在关注本教程:https ://github.com/grommet/grommet-standalone但我收到以下错误:

ERROR in ./src/app/index.js
Module not found: Error: Can't resolve 'grommet/scss/vanilla/index' in '/home/john/Development/Work/Utilities/react_practice/test_app/src/app'
 @ ./src/app/index.js 31:0-37
 @ multi library

显然,它在源目录而不是 node_modules 中寻找 scss 文件 - 但我不知道是什么导致了错误或如何修复它。

我正在使用这个 sass 加载器:https ://github.com/jtangelder/sass-loader

因为这个,我正在使用 webpack 2.10:https ://stackoverflow.com/a/39608145/1596288

此外,这些是我的 webpack.config.babel.js 和 index.js 文件:

import webpack from 'webpack';

module.exports = {
    entry: {
        library: './src/app/index.js',
    },

    output: {
        library: 'bundle',
        libraryTarget: 'umd',
        filename: 'bundle.js',
        path: './public/dist'
    },

    devServer : {
        inline: true,
        contentBase: './public',
        port: 8100
    },

    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                query: {
                    presets: ['es2015', 'react']
                }
            },

            {
                test: /\.scss$/,
                loader: 'style!css!sass?outputStyle=compressed'
            }
        ]
    },

    sassLoader: {
        sourceMap: true,
        includePaths: [
            './node_modules',
            './node_modules/grommet/node_modules'
        ]
    }
}

和 ...

import Header from 'grommet/components/Header';
import Title from 'grommet/components/Title';
import Box from 'grommet/components/Box';
import Search from 'grommet/components/Search';
import Menu from 'grommet/components/Menu';
import Anchor from 'grommet/components/Anchor';
import Actions from 'grommet/components/icons/base/Actions'

import 'grommet/scss/vanilla/index';

import React from 'react'
import { render } from 'react-dom'

const TesterComponent = () => (
   <Header>
        <Title>
            Sample Title
        </Title>

        <Box flex={true}
        justify='end'
        direction='row'
        responsive={false}>
            <Search inline={true}
            fill={true}
            size='medium'
            placeHolder='Search'
            dropAlign={{"right": "right"}} />

            <Menu icon={<Actions />}
            dropAlign={{"right": "right"}}>
                <Anchor href='#'
                    className='active'>
                    First
                </Anchor>
                <Anchor href='#'>
                    Second
                </Anchor>
                <Anchor href='#'>
                    Third
                </Anchor>
            </Menu>
        </Box>
    </Header>
)


render (
    <TesterComponent />,
    document.getElementById('root')
)
4

2 回答 2

0

通过首先将我的 webpack.config.babel.js 修改为以下内容,设法解决了这个问题:

import webpack from 'webpack';

module.exports = {
entry: {
    library: './src/app/index.js',
},

output: {
    library: 'bundle',
    libraryTarget: 'umd',
    filename: 'bundle.js',
    path: './public/dist'
},

devServer : {
    inline: true,
    contentBase: './public',
    port: 8100
},

resolve: {
    extensions: ['', '.js', '.scss', '.css']
},

module: {
    loaders: [
        {
            test: /\.jsx?$/,
            loader: 'babel-loader',
            exclude: /node_modules/,
            query: {
                presets: ['es2015', 'react']
            }
        },

        {
            test: /\.scss$/,
            loader: 'style-loader!css-loader!sass-loader?outputStyle=compressed'
        }
    ]
},

sassLoader: {
    includePaths: [
        './node_modules',
        './node_modules/grommet/node_modules'
    ]
}

}

确保您也安装了以下库:

sudo npm install style-loader --save-dev
sudo npm install css-loader --save-dev
sudo npm install sass-loader --save-dev
于 2017-02-03T10:35:34.593 回答
0

尝试这个

{
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract('style-loader', "css-loader!postcss-loader!sass-loader")
      },
于 2017-02-04T23:40:52.897 回答