Configuración de paquete web con bootstrap

2

Utilizo el paquete web con bootstrap, pero no puedo obtener fuentes de bootstrap en mi aplicación.

La ruta /Users/and/devel/webpack_bootstrap/es la carpeta raíz del proyecto.

Recibo errores:

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

Archivos

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

se generan en la /Users/and/devel/webpack_bootstrap/distcarpeta después de la compilación

Traté de arranque-webpack , pero todavía consigo los mismos errores.

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 -> script -> index.js

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

Editar: uso esta configuración de paquete web y todo funciona.

11
1

Debes tener esta estructura en tu código:

  • index.html
    • dist /
      • index.js
      • fuentes ....

Está cargando index.js desde index.html, pero el paquete web no sabe dónde está la ruta pública y usa la ruta raíz predeterminada. Cambie la salida respectiva a algo como esto:

output: {
    path: path.join(__dirname, './dist'),
    filename: '[name].js',
    sourceMapFilename: "[file].map",
    publicPath: '/dist'
},
1
+50

Para que funcione el bootstrap-webpack-example, fue necesario realizar un par de arreglos de configuración. Puedes intentar clonar y construir esta bifurcación de github por ahora en https://github.com/fagiani/bootstrap-webpack-example

Asegúrate de usar el gulp buildcomando. Para instalar todas las dependencias que necesita usar npm install --save-devdespués de haber instalado gulp, puede ver los detalles aquí: github.com/gulpjs/gulp/blob/master/docs/getting-started.md

En el proyecto anterior, la entrada se establece en el archivo karma.conf.js que llama a webpack.config.js.