代码之家  ›  专栏  ›  技术社区  ›  Oleg Shleif

带有引导的网页包。css不工作

  •  1
  • Oleg Shleif  · 技术社区  · 7 年前

    这是我的 webpack.config.js 文件:

    var ExtractTextPlugin = require('extract-text-webpack-plugin'),
        webpack = require('webpack');
    
    module.exports = {
        entry: [
            './src/app.js',
        ],
        output: {
            path: __dirname + '/../web/js',
            filename: 'build.js',
        },
        module: {
            loaders: [
                {
                    test: /\.js$/,
                    exclude: /node_modules/,
                    loader: 'babel-loader'
                },
                {
                    test: /\.css$/,
                    loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
                },
                {
                    test: /\.(png|woff|woff2|eot|ttf|svg)$/,
                    loader: "url?limit=5000"
                }
            ]
        },
        plugins: [
            new webpack.ProvidePlugin({
                $: "jquery",
                jQuery: "jquery"
            }),
            new ExtractTextPlugin('build.css')
        ]
    }
    

    这是我的 文件:

    "dependencies": {
        "angular": "^1.6.4",
        "babel-core": "^6.25.0",
        "babel-loader": "^7.1.1",
        "babel-polyfill": "^6.23.0",
        "babel-preset-es2015": "^6.24.1",
        "bootstrap": "^3.3.7",
        "css-loader": "^0.28.4",
        "extract-text-webpack-plugin": "^3.0.0",
        "file-loader": "^0.11.2",
        "jquery": "^3.2.1",
        "style-loader": "^0.18.2",
        "url-loader": "^0.5.9",
        "webpack": "^3.4.1"
    }
    

    app.js

    import 'babel-polyfill';
    import $ from 'jquery';
    import 'bootstrap/dist/js/bootstrap.js';
    import 'bootstrap/dist/css/bootstrap.css';
    

    在尝试启动网页后,我出现了一个错误。

    ERROR in ./node_modules/bootstrap/dist/css/bootstrap.css Module parse failed:
    /var/www/dcracks/app/webpack/node_modules/bootstrap/dist/css/bootstrap.css
    Unexpected token (7:5) You may need an appropriate loader to handle this file type.
      |  */
      | /*! normalize.css v3.0.3
      | MIT License
      | github.com/necolas/normalize.css */
      | html {
      |   font-family: sans-serif;
      |   -webkit-text-size-adjust: 100%;
      @ ./node_modules/bootstrap/dist/css/bootstrap.css 4:14-42
      @ ./src/app.js  @ multi ./src/app.js
    

    我重读了一堆材料,在各种论坛上发表了一堆帖子。 我做错了什么?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Michael Jungo    7 年前

    signature of ExtractTextPlugin.extract 是:

    ExtractTextPlugin.extract(options: loader | object)
    

    css-loader 未被使用。最常见的配置是使用 style-loader

    您可以使用中显示的规则 Readme - Usage .

    {
      test: /\.css$/,
      use: ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: 'css-loader'
      })
    }