首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置webpack 4的反应js与bootstrap4,字体-可怕和saas?

如何设置webpack 4的反应js与bootstrap4,字体-可怕和saas?
EN

Stack Overflow用户
提问于 2018-03-31 09:00:54
回答 1查看 1K关注 0票数 1

我需要帮助,在设置webpack 4的反应js与bootstrap4,字体可怕和sass。我按照下面的教程来启动我的项目,它运行得很好,但是我也想使用bootstrap4和字体。

https://www.valentinog.com/blog/webpack-4-tutorial/

也尝试过这样做,但是这是针对webpack 3的,有些依赖/插件与v4不兼容。

https://medium.com/@estherfalayi/setting-up-webpack-for-bootstrap-4-and-font-awesome-eb276e04aaeb

我尽我所能配置webpack,学习多个指南和教程

webpack.config.js

代码语言:javascript
复制
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const precss = require('precss');
const path = require('path');

const TransferWebpackPlugin = require('transfer-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

var BUILD_DIR = path.resolve(__dirname, 'build');
var APP_DIR = path.resolve(__dirname, 'src/js');

var config = {
  entry: [
    APP_DIR + '/index.js',
    'tether',
    'font-awesome/scss/font-awesome.scss'
  ],
  output: {
    path: BUILD_DIR,
    filename: "js/bundle.js"
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader"
        }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: { minimize: true }
          }
        ]
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, "css-loader"]
      }
    ]

  },
  {
    test: /font-awesome\.config\.js/,
    use: [
      { loader: 'style-loader' },
      { loader: 'font-awesome-loader' }
    ]
    // Bootstrap 4
    {
      test: /bootstrap\/dist\/js\/umd\//, use: 'imports-loader?jQuery=jquery'
    }
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html"
    }),
    new MiniCssExtractPlugin({
      filename: "[name].css",
      chunkFilename: "[id].css"
    })
    new webpack.HotModuleReplacementPlugin(),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery',
      tether: 'tether',
      Tether: 'tether',
      'window.Tether': 'tether',
      Popper: ['popper.js', 'default'],
      'window.Tether': 'tether',
      Alert: 'exports-loader?Alert!bootstrap/js/dist/alert',
      Button: 'exports-loader?Button!bootstrap/js/dist/button',
      Carousel: 'exports-loader?Carousel!bootstrap/js/dist/carousel',
      Collapse: 'exports-loader?Collapse!bootstrap/js/dist/collapse',
      Dropdown: 'exports-loader?Dropdown!bootstrap/js/dist/dropdown',
      Modal: 'exports-loader?Modal!bootstrap/js/dist/modal',
      Popover: 'exports-loader?Popover!bootstrap/js/dist/popover',
      Scrollspy: 'exports-loader?Scrollspy!bootstrap/js/dist/scrollspy',
      Tab: 'exports-loader?Tab!bootstrap/js/dist/tab',
      Tooltip: "exports-loader?Tooltip!bootstrap/js/dist/tooltip",
      Util: 'exports-loader?Util!bootstrap/js/dist/util'
    }),
  ]
};

module.exports = config;
EN

回答 1

Stack Overflow用户

发布于 2018-03-31 09:07:34

一些webpack插件不支持webacpk4。插件需要使用测试版.

以下是我使用webpack4的解决方案。https://github.com/Rukeith/blog-website/blob/develop/webpack.common.js

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49586055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档