webpack不包含CSS文件

时间:2019-01-20 12:18:25

标签: javascript css reactjs webpack

我已经构建了一个react-stepper并将其上传到github。 当我想构建我的App时,webpack不包含超棒的CSS。但是它包括我自己的style.scss文件。我在webpack中使用样式加载器。 在开发模式下,一切正常。仅在构建模式下不起作用。 这是我的仓库:

https://github.com/tkwant/react-stepper-wizard

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

const webpack = require("webpack");
const CleanWebpackPlugin = require("clean-webpack-plugin");

module.exports = {
  entry: "./src/index.js",
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: ["babel-loader"]
      },
      {
        test: /\.(scss|css)$/,
        use: [
          {
            loader: "style-loader" // creates style nodes from JS strings
          },
          {
            loader: "css-loader" // translates CSS into CommonJS
          },
          {
            loader: "sass-loader" // compiles Sass to CSS
          }
        ]
      },
      {
        test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: "url-loader?limit=10000&mimetype=application/font-woff"
      },
      {
        test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
        loader: "file-loader"
      }
    ]
  },
  resolve: {
    extensions: ["*", ".js", ".jsx"]
  },
  output: {
    path: __dirname + "/dist",
    publicPath: "/",
    filename: "react-stepper-wizard.js",
    library: "Stepper",
    libraryTarget: "umd"
  },
  externals: ["react", "react-dom", "font-awesome"],
  plugins: [
    new CleanWebpackPlugin(["dist"]),
    new webpack.HotModuleReplacementPlugin()
  ],
  devtool: "source-map",
  devServer: {
    contentBase: "./examples",
    hot: true,
    port: 9001
  }
};

如果有人可以在这里帮助我或者可以进行PR来解决此问题,那将是很好的。

2 个答案:

答案 0 :(得分:1)

您正在复制python file.py PAUSE python file.py PAUSE python file.py PAUSE (...) python file.py PAUSE 文件,对吗? 您可能需要尝试webpack-copy-plugin

答案 1 :(得分:0)

解决方案是使用url加载程序。

 { test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader" },
  { test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader" },