使用引导程序配置Webpack

马特

我将Webpack与bootstrap一起使用,但是无法在我的应用程序中获取bootstrap字体。

路径/Users/and/devel/webpack_bootstrap/是项目的根文件夹。

我收到错误消息:

jquery.js:9077 GET file:///Users/and/devel/webpack_bootstrap/448c34a56d699c29117adc64c43affeb.woff2 net::ERR_FILE_NOT_FOUND
GET file:///Users/and/devel/webpack_bootstrap/fa2772327f55d8198301fdb8bcfc8158.woff net::ERR_FILE_NOT_FOUND
GET file:///Users/and/devel/webpack_bootstrap/e18bbf611f2a2e43afc071aa2f4e1512.ttf net::ERR_FILE_NOT_FOUND

档案

448c34a56d699c29117adc64c43affeb.woff2, fa2772327f55d8198301fdb8bcfc8158.woff, e18bbf611f2a2e43afc071aa2f4e1512.ttf

/Users/and/devel/webpack_bootstrap/dist编译后生成到文件夹中

我尝试了bootstrap-webpack,但是仍然遇到相同的错误。

package.json

{
  "name": "Webpack_bootstrap",
  "version": "1.0.0",
  "description": "webpack bootstrap test",
  "main": "index.js",
  "scripts": {
    "start": "npm run serve | npm run dev",
    "serve": "./node_modules/.bin/http-server -p 8080",
    "dev": "webpack-dev-server -d --progress --colors --port 8090"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "bootstrap": "^3.3.6",
    "bootstrap-select": "^1.9.3",
    "bootstrap-table": "^1.9.1",
    "bootstrap-webpack": "0.0.5",
    "bower-webpack-plugin": "^0.1.9",
    "css-loader": "^0.23.0",
    "eonasdan-bootstrap-datetimepicker": "^4.15.35",
    "events": "^1.1.0",
    "exports-loader": "^0.6.2",
    "extract-text-webpack-plugin": "^0.9.1",
    "file-loader": "^0.8.5",
    "http-server": "^0.8.5",
    "jquery": "^2.1.4",
    "jquery-resizable-columns": "^0.2.3",
    "jquery-slimscroll": "^1.3.6",
    "jquery-ui": "^1.10.5",
    "less": "^2.5.3",
    "less-loader": "^2.2.2",
    "lodash": "^3.10.1",
    "moment": "^2.10.6",
    "node-sass": "^3.4.2",
    "object-assign": "^4.0.1",
    "path": "^0.12.7",
    "sass-loader": "^3.1.2",
    "select2": "^4.0.1",
    "select2-bootstrap-css": "^1.4.6",
    "style-loader": "^0.13.0",
    "svg-sprite-loader": "0.0.15",
    "typeahead.js": "^0.11.1",
    "url-loader": "^0.5.7",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  }
}

webpack.config.js

var CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
var BowerWebpackPlugin = require("bower-webpack-plugin");
var path = require('path');

module.exports = {
    cache: true,
    entry: {
      index: './src/script/index.js'
    },
    output: {
        path: path.join(__dirname, './dist'),
        filename: '[name].js',
        sourceMapFilename: "[file].map"
    },
    debug: true,
    devtool: 'source-map',
    module: {
      loaders: [
      // **IMPORTANT** This is needed so that each bootstrap js file required by
      // bootstrap-webpack has access to the jQuery object
      { test: /bootstrap\/js\//, loader: 'imports?jQuery=jquery' },

      // Needed for the css-loader when [bootstrap-webpack](https://github.com/bline/bootstrap-webpack)
      // loads bootstrap's css.
      {
        test: /\.scss$/,
        loaders: [ 'style', 'css', 'sass' ]
      },
      {
        test: /\.less$/,
        loaders: [ 'style', 'css', 'less' ]
      },
      {
        test: /\.css$/,
        loaders: [ 'style', 'css']
      },
      {test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff'},
      {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
      {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
      {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'}
    ]
    },
    plugins: [
        new BowerWebpackPlugin(),
        new CommonsChunkPlugin('index', 'index.js', Infinity)
    ],
    resolve: {
        extensions: ['', '.js', '.jsx']
    }
};

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Won</title>
</head>
<body>

    <script type="text/javascript" src="./dist/index.js"></script>

    <div id="content">

      <!-- Button trigger modal -->
      <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
        Launch demo modal
      </button>

      <!-- Modal -->
      <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">
              <button type="button" class="btn btn-default btn-lg">
                <span class="glyphicon glyphicon-star" aria-hidden="true"></span> Star
              </button>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
              <button type="button" class="btn btn-primary">Save changes</button>
            </div>
          </div>
        </div>
      </div>

</body>
</html>

src->脚本-> index.js

var bootstrap = require('bootstrap-webpack');

编辑:我使用此webpack配置,一切正常。

为了使bootstrap-webpack-example示例正常工作,需要进行一些配置修复。您可以在https://github.com/fagiani/bootstrap-webpack-example上尝试克隆和构建此github分支

确保使用gulp build命令。要安装所有npm install --save-dev安装了gulp的文件,您可以在此处查看详细信息:github.com/gulpjs/gulp/blob/master/docs/getting-started.md

在以上项目中,该条目在karma.conf.js文件中设置,该文件调用webpack.config.js。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法使引导程序与Webpack一起使用

来自分类Dev

使用引导程序的Webpack-未定义jquery

来自分类Dev

使用webpack / laravel混合的自定义引导程序?

来自分类Dev

Kickstart配置-被忽略的isk和引导程序使用

来自分类Dev

Webpack +打字稿+引导程序

来自分类Dev

与 Webpack + Jquery + 引导程序反应

来自分类Dev

使用引导程序对齐

来自分类Dev

使用引导程序对齐

来自分类Dev

使用请求配置Webpack

来自分类Dev

DropWizard引导程序vs配置vs环境

来自分类Dev

kickstart引导加载程序--driveorder配置

来自分类Dev

使用Rails安装引导程序

来自分类Dev

除了jQuery还使用引导程序?

来自分类Dev

仅使用引导程序的轮播

来自分类Dev

使用引导程序滑动列

来自分类Dev

使用引导程序缩放图像

来自分类Dev

使用引导程序的中心块

来自分类Dev

使用引导程序设置按钮

来自分类Dev

流星下拉?使用引导程序

来自分类Dev

使用angularjs引导程序分页

来自分类Dev

使用引导程序创建布局

来自分类Dev

使用引导程序隐藏显示

来自分类Dev

使用引导程序的类别部分

来自分类Dev

使用引导程序居中图像

来自分类Dev

React 应用程序的 Webpack 配置

来自分类Dev

Ionic 2:将配置属性移入引导程序

来自分类Dev

导轨:在导轨上安装和配置引导程序6

来自分类Dev

ZfcTwig未加载配置,并且在引导程序中失败

来自分类Dev

Ionic 2:将配置属性移入引导程序