【问题标题】:webpack css loader with reason-react带有原因反应的 webpack css 加载器
【发布时间】:2019-02-14 14:17:47
【问题描述】:

我正在努力让 webpack 与我的原因应用程序一起工作。

我已经使用以下命令安装了 webpack:

npm install --save-dev webpack

我已经使用以下命令安装了 style-loader 和 css-loader:

npm install --save-dev style-loader css-loader

这是我的 package.json 文件的示例:

 "devDependencies": {
    "bs-platform": "^4.0.18",
    "css-loader": "^2.1.0",
    "html-webpack-plugin": "^3.2.0",
    "style-loader": "^0.23.1",
    "sw-precache-webpack-plugin": "^0.11.5",
    "webpack": "^4.29.3",
    "webpack-cli": "^3.2.3",
    "webpack-dev-server": "^3.1.14",
    "webpack-pwa-manifest": "^4.0.0"
  },
  "dependencies": {
    "react": "^16.8.1",
    "react-dom": "^16.8.1",
    "reason-react": ">=0.5.3"
  }

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

const outputDir = path.join(__dirname, 'build/');

module.exports = {
  entry: './src/Index.bs.js',
  mode: isProd ? 'production' : 'development',
  output: {
    path: outputDir,
    filename: 'index.js',
    publicPath: PUBLIC_PATH
  },
  module: {
    rules: [{
      test: /\.css$/,
      use: [
        { loader: "style-loader" },
        { loader: "css-loader" }
      ]
    }]
  },

我已将以下命令添加到我的 Index.re 文件中以加载我的 css 文件:

[%raw {|require('../css/index.css')|}] 

这里是生成的js文件:

// Generated by BUCKLESCRIPT VERSION 4.0.18, PLEASE EDIT WITH CARE
'use strict';

var Component1 = require("./Component1.bs.js");
var ReactDOMRe = require("reason-react/src/ReactDOMRe.js");
var ReasonReact = require("reason-react/src/ReasonReact.js");

((require('../css/index.css')));

ReactDOMRe.renderToElementWithId(ReasonReact.element(undefined, undefined, Component1.make("Hello!", /* array */[])), "index1");

/*  Not a pure module */

我在启动 webpack 时没有任何错误,但是我的 css 文件没有在“build”文件夹中生成... 这是我的项目文件夹:

【问题讨论】:

    标签: css webpack reason reason-react


    【解决方案1】:

    它不会生成,因为 style-loader 在样式标签上按需添加到您的 html 文件头。

    要生成物理css文件,请使用mini-css-extract-plugin

    【讨论】:

      猜你喜欢
      • 2017-10-05
      • 2018-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-01-23
      • 2019-07-08
      • 2018-03-03
      • 1970-01-01
      • 2021-12-06
      相关资源
      最近更新 更多