Twitter bootstrap 使用引导css创建React应用程序

Twitter bootstrap 使用引导css创建React应用程序,twitter-bootstrap,reactjs,webpack,Twitter Bootstrap,Reactjs,Webpack,我正在使用CreateReact应用程序,希望将引导css包含到我的项目中。我看到了在CreateReact应用程序github上包含React引导的说明,但我只寻找常规引导,而不是React引导 我已经通过npm安装了bootstrap,并且像这样将它包含在我的index.js文件中 import 'bootstrap/dist/css/bootstrap.css' 当我运行开始脚本时,这似乎部分起作用。字体似乎使用引导,但仅此而已,即其他引导CSS似乎都不起作用 我在尝试构建时遇到以下错误

我正在使用CreateReact应用程序,希望将引导css包含到我的项目中。我看到了在CreateReact应用程序github上包含React引导的说明,但我只寻找常规引导,而不是React引导

我已经通过npm安装了bootstrap,并且像这样将它包含在我的index.js文件中

import 'bootstrap/dist/css/bootstrap.css'
当我运行开始脚本时,这似乎部分起作用。字体似乎使用引导,但仅此而已,即其他引导CSS似乎都不起作用

我在尝试构建时遇到以下错误

Module not found: Error: Cannot resolve module '[object Object]' in /Users/username/Sites/Learning/modular
/src
我猜这和字体有关。我在修改webpack配置以允许引导字体时遇到了一些困难

有人能做到这一点吗

我使用的是与CreateReact应用程序附带的相同的网页包配置。但是,我修改了CSS加载程序,使其能够加载SASS,并且能够加载SASS/CSS模块。我已经测试过,只需要一个完整的样式表而不使用CSS模块仍然有效

var autoprefixer = require("autoprefixer");
var webpack = require("webpack");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
var InterpolateHtmlPlugin = require("react-dev-utils/InterpolateHtmlPlugin");
var WatchMissingNodeModulesPlugin = require(
  "react-dev-utils/WatchMissingNodeModulesPlugin"
);
var getClientEnvironment = require("./env");
var paths = require("./paths");

// Webpack uses `publicPath` to determine where the app is being served from.
// In development, we always serve from the root. This makes config easier.
var publicPath = "/";
// `publicUrl` is just like `publicPath`, but we will provide it to our app
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
var publicUrl = "";
// Get environment variables to inject into our app.
var env = getClientEnvironment(publicUrl);

// This is the development configuration.
// It is focused on developer experience and fast rebuilds.
// The production configuration is different and lives in a separate file.
module.exports = {
  // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
  // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
  devtool: "cheap-module-source-map",
  // These are the "entry points" to our application.
  // This means they will be the "root" imports that are included in JS bundle.
  // The first two entry points enable "hot" CSS and auto-refreshes for JS.
  entry: [
    // Include an alternative client for WebpackDevServer. A client's job is to
    // connect to WebpackDevServer by a socket and get notified about changes.
    // When you save a file, the client will either apply hot updates (in case
    // of CSS changes), or refresh the page (in case of JS changes). When you
    // make a syntax error, this client will display a syntax error overlay.
    // Note: instead of the default WebpackDevServer client, we use a custom one
    // to bring better experience for Create React App users. You can replace
    // the line below with these two lines if you prefer the stock client:
    // require.resolve('webpack-dev-server/client') + '?/',
    // require.resolve('webpack/hot/dev-server'),
    require.resolve("react-dev-utils/webpackHotDevClient"),
    // We ship a few polyfills by default:
    require.resolve("./polyfills"),
    // Finally, this is your app's code:
    paths.appIndexJs
    // We include the app code last so that if there is a runtime error during
    // initialization, it doesn't blow up the WebpackDevServer client, and
    // changing JS code would still trigger a refresh.
  ],
  output: {
    // Next line is not used in dev but WebpackDevServer crashes without it:
    path: paths.appBuild,
    // Add /* filename */ comments to generated require()s in the output.
    pathinfo: true,
    // This does not produce a real file. It's just the virtual path that is
    // served by WebpackDevServer in development. This is the JS bundle
    // containing code from all our entry points, and the Webpack runtime.
    filename: "static/js/bundle.js",
    // This is the URL that app is served from. We use "/" in development.
    publicPath: publicPath
  },
  resolve: {
    // This allows you to set a fallback for where Webpack should look for modules.
    // We read `NODE_PATH` environment variable in `paths.js` and pass paths here.
    // We use `fallback` instead of `root` because we want `node_modules` to "win"
    // if there any conflicts. This matches Node resolution mechanism.
    // https://github.com/facebookincubator/create-react-app/issues/253
    fallback: paths.nodePaths,
    // These are the reasonable defaults supported by the Node ecosystem.
    // We also include JSX as a common component filename extension to support
    // some tools, although we do not recommend using it, see:
    // https://github.com/facebookincubator/create-react-app/issues/290
    extensions: [".js", ".json", ".jsx", ""],
    alias: {
      // Support React Native Web
      // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
      "react-native": "react-native-web"
    }
  },

  module: {
    // First, run the linter.
    // It's important to do this before Babel processes the JS.
    preLoaders: [
      {
        test: /\.(js|jsx)$/,
        loader: "eslint",
        include: paths.appSrc
      }
    ],
    loaders: [
      // ** ADDING/UPDATING LOADERS **
      // The "url" loader handles all assets unless explicitly excluded.
      // The `exclude` list *must* be updated with every change to loader extensions.
      // When adding a new loader, you must add its `test`
      // as a new entry in the `exclude` list for "url" loader.

      // "url" loader embeds assets smaller than specified size as data URLs to avoid requests.
      // Otherwise, it acts like the "file" loader.
      {
        exclude: [/\.html$/, /\.(js|jsx)$/, /\.css$/, /\.json$/, /\.svg$/],
        loader: "url",
        query: {
          limit: 10000,
          name: "static/media/[name].[hash:8].[ext]"
        }
      },
      // Process JS with Babel.
      {
        test: /\.(js|jsx)$/,
        include: paths.appSrc,
        loader: "babel",
        query: {
          // This is a feature of `babel-loader` for webpack (not Babel itself).
          // It enables caching results in ./node_modules/.cache/babel-loader/
          // directory for faster rebuilds.
          cacheDirectory: true
        }
      },
      // "postcss" loader applies autoprefixer to our CSS.
      // "css" loader resolves paths in CSS and adds assets as dependencies.
      // "style" loader turns CSS into JS modules that inject <style> tags.
      // In production, we use a plugin to extract that CSS to a file, but
      // in development "style" loader enables hot editing of CSS.
      {
        test: /\.css$/,
        loaders: [
          "style?sourceMap",
          "css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]",
          "resolve-url",
          "sass?sourceMap"
        ]
      },
      // JSON is not enabled by default in Webpack but both Node and Browserify
      // allow it implicitly so we also enable it.
      {
        test: /\.json$/,
        loader: "json"
      },
      // "file" loader for svg
      // {
      //   test: /\.svg$/,
      //   loader: "file",
      //   query: {
      //     name: "static/media/[name].[hash:8].[ext]"
      //   }
      // },
      {
        test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
        loader: "url"
      },
      {
        test: /\.(eot|ttf|wav|mp3)$/,
        loader: "file"
      }

      // ** STOP ** Are you adding a new loader?
      // Remember to add the new extension(s) to the "url" loader exclusion list.
    ]
  },

  // We use PostCSS for autoprefixing only.
  postcss: function() {
    return [
      autoprefixer({
        browsers: [
          ">1%",
          "last 4 versions",
          "Firefox ESR",
          "not ie < 9" // React doesn't support IE8 anyway
        ]
      })
    ];
  },
  plugins: [
    // Makes some environment variables available in index.html.
    // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
    // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
    // In development, this will be an empty string.
    new InterpolateHtmlPlugin(env.raw),
    // Generates an `index.html` file with the <script> injected.
    new HtmlWebpackPlugin({
      inject: true,
      template: paths.appHtml
    }),
    // Makes some environment variables available to the JS code, for example:
    // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
    new webpack.DefinePlugin(env.stringified),
    // This is necessary to emit hot updates (currently CSS only):
    new webpack.HotModuleReplacementPlugin(),
    // Watcher doesn't work well if you mistype casing in a path so we use
    // a plugin that prints an error when you attempt to do this.
    // See https://github.com/facebookincubator/create-react-app/issues/240
    new CaseSensitivePathsPlugin(),
    // If you require a missing module and then `npm install` it, you still have
    // to restart the development server for Webpack to discover it. This plugin
    // makes the discovery automatic so you don't have to restart.
    // See https://github.com/facebookincubator/create-react-app/issues/186
    new WatchMissingNodeModulesPlugin(paths.appNodeModules)
  ],
  // Some libraries import Node modules but don't use them in the browser.
  // Tell Webpack to provide empty mocks for them so importing them works.
  node: {
    fs: "empty",
    net: "empty",
    tls: "empty"
  }
};
var autoprefixer=require(“autoprefixer”);
var webpack=需要(“webpack”);
var HtmlWebpackPlugin=require(“html网页包插件”);
var CaseSensitivePathsPlugin=require(“区分大小写的路径网页包插件”);
var InterpolateHtmlPlugin=require(“react dev utils/InterpolateHtmlPlugin”);
var watchmissingdemodulesplugin=require(
“react dev utils/WatchMissingNodeModulesPlugin”
);
var getClientEnvironment=require(“/env”);
变量路径=需要(“./路径”);
//Webpack使用“publicPath”确定应用程序的服务来源。
//在发展中,我们始终从根本上服务。这使得配置更容易。
var publicPath=“/”;
//“publicUrl”与“publicPath”类似,但我们会将其提供给我们的应用程序
//作为'index.html'中的%PUBLIC_URL%和JavaScript中的'process.env.PUBLIC_URL'。
//省略尾随斜杠,因为%PUBLIC\u PATH%/xyz看起来比%PUBLIC\u PATH%xyz好。
var publicUrl=“”;
//获取要注入到我们的应用程序中的环境变量。
var env=getClientEnvironment(publicUrl);
//这是开发配置。
//它专注于开发人员体验和快速重建。
//生产配置是不同的,存在于单独的文件中。
module.exports={
//如果希望在DevTools中查看编译后的输出,则可能需要使用“eval”。
//请参阅中的讨论https://github.com/facebookincubator/create-react-app/issues/343.
devtool:“廉价模块源代码映射”,
//这些是我们应用程序的“入口点”。
//这意味着它们将是JS包中包含的“根”导入。
//前两个入口点为JS启用“热”CSS和自动刷新。
条目:[
//包括WebpackDevServer的备用客户端。客户端的作业是
//通过套接字连接到WebpackDevServer,并获得有关更改的通知。
//保存文件时,客户端将应用热更新(如果
//或刷新页面(如果是JS更改)
//如果出现语法错误,此客户端将显示语法错误覆盖。
//注意:我们使用的不是默认的WebpackDevServer客户端,而是自定义客户端
//为Create React应用程序用户带来更好的体验。您可以替换
//如果您更喜欢股票客户,请使用以下两行:
//require.resolve('webpack-dev-server/client')+“?/”,
//require.resolve('webpack/hot/dev server'),
require.resolve(“react dev utils/webpackHotDevClient”),
//默认情况下,我们会提供一些多边形填充:
要求。解决(“./polyfills”),
//最后,这是您的应用程序代码:
path.appIndexJs
//我们最后包含应用程序代码,以便在
//初始化时,它不会炸毁WebpackDevServer客户端,并且
//更改JS代码仍然会触发刷新。
],
输出:{
//下一行未在dev中使用,但WebpackDevServer在没有它的情况下崩溃:
路径:path.appBuild,
//向输出中生成的require()添加/*filename*/注释。
是的,
//这不会生成真正的文件,它只是虚拟路径
//由开发中的WebpackDevServer提供服务。这是JS包
//包含来自所有入口点的代码,以及Webpack运行时。
文件名:“static/js/bundle.js”,
//这是应用服务的URL。我们在开发中使用“/”。
公共路径:公共路径
},
决心:{
//这允许您为Webpack应该查找模块的位置设置回退。
//我们在'PATH.js'中读取'NODE_PATH'环境变量,并在此处传递路径。
//我们使用'fallback'而不是'root',因为我们希望'node_modules'能够“赢”
//如果存在任何冲突。这与节点解决机制匹配。
// https://github.com/facebookincubator/create-react-app/issues/253
后退:路径。节点路径,
//这些是节点生态系统支持的合理默认值。
//我们还包括JSX作为通用组件文件扩展名,以支持
//尽管我们不建议使用某些工具,但请参见:
// https://github.com/facebookincubator/create-react-app/issues/290
扩展名:[“.js”、“.json”、“.jsx”、”“],
别名:{
//支持本地Web
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
“反应本机”:“反应本机web”
}
},
模块:{
//首先,运行门楣。
//在巴贝尔处理JS之前这样做很重要。
预紧器:[
{
测试:/\(js|jsx)$/,
加载器:“eslint”,
包括:path.appSrc
}
],
装载机:[
//**添加/更新加载程序**
//“url”加载器处理所有资产,除非明确排除。
//“排除”列表*必须*随着加载程序扩展的每次更改而更新。
//添加新加载程序时,必须添加其“测试”`
//作为“url”加载程序的“排除”列表中的新条目。
//“url”加载器嵌入小资产
import '~bootstrap/dist/css/bootstrap.css'