Guilherme Chiara Guilherme Chiara - 4 months ago 79
Node.js Question

Webpack and Bootstrap problems

I'm quite new to Webpack and NodeJS, so I'm doing simple tests just to learn. I'm developing a new website and here's my idea:

I have a vendor.ts file that I can put all my vendors js and css:



// Angular 2
import '@angular/platform-browser';
import '@angular/platform-browser-dynamic';
import '@angular/core';
import '@angular/common';
import '@angular/http';
import '@angular/router';

// RxJS
import 'rxjs';

// Bootstrap
import 'bootstrap';
import '../node_modules/bootstrap/dist/css/bootstrap.css';

//jQuery
import 'jquery';





So, here's my webpack config:



var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');


module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/app/main.ts'
},

output: {
path: './src/public/',
publicPath: 'http://localhost:3000/',
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},

devtool: 'cheap-module-eval-source-map',

resolve: {
extensions: ['', '.js', '.ts']
},

module: {
loaders: [
{
test: /\.ts$/,
loaders: ['ts', 'angular2-template-loader']
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({fallbackLoader: "style-loader", loader: "css-loader?souceMap"})
},
],
plugins: [
new ExtractTextPlugin("[name].css")
]
},

plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),

new HtmlWebpackPlugin({
template: './src/index.html'
}),

new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
]
};





When I'm running 'webpack' command, it throws me the error:


ERROR in ./src/vendor.ts Module not found: Error: Cannot resolve
module '[object Object]' in /home/xxxxx/xxxx/xxxxx-xxxx/src @
./src/vendor.ts 13:0-59


Does anybody could help me?

Thanks!

EDIT: the solution can be find at https://github.com/webpack/extract-text-webpack-plugin/issues/215

Answer

It is wrong to do so import '../node_modules/bootstrap/dist/css/bootstrap.css'. With non-code files you have to use require instead, like require( '../node_modules/bootstrap/dist/css/bootstrap.css').

This article could be helpful https://webpack.github.io/docs/stylesheets.html