1
votes

I'm running into a problem while using Webpack to include bootstrap.css into my entry js file.

i have a entry js file, named app.js, which is used to load an external css name app.css and bootstrap css

require("../node_modules/bootstrap/dist/css/bootstrap.css");
require("../css/app.css");

So the bootstrap lib , i get it from npm and put it into node_modules repo.

So here is my webpack config

var path = require('path');
var webpack = require('webpack');

module.exports = {
    context: path.resolve('js'),
    entry: ["./app.js"], 
    output: {
        path: path.resolve('build/js/'),
        publicPath: '/assets/js/',  
        filename: "bundle.js"
    },
    devtool: "source-map",
    devServer: {
        contentBase: 'public'
    },
    watch: true,
    module: {
        loaders: [
            {
                test: /\.es6\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader'
            },
            {
                test: /\.css$/,
                loader: "style-loader!css-loader"
            },
            { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: "file" },
            { test: /\.(woff|woff2)$/, loader:"url?prefix=font/&limit=5000" },
            { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=application/octet-stream" },
            { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: "url?limit=10000&mimetype=image/svg+xml" }
        ]
    },
    resolve: {
        extensions: ['', '.js', '.es6.js']
    }
}

When i run webpack, there is an error happens

ERROR in ../~/bootstrap/dist/css/bootstrap.css
Module parse failed: /front-end/Webpack/node_modules/bootstrap/dist/css/bootstrap.css Unexpected token (7:5)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (7:5)
    at Parser.pp$4.raise (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:2221:15)
    at Parser.pp.unexpected (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:603:10)
    at Parser.pp.semicolon (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:581:61)
    at Parser.pp$1.parseExpressionStatement (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:966:10)
    at Parser.pp$1.parseStatement (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:730:24)
    at Parser.pp$1.parseTopLevel (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:638:25)
    at Parser.parse (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:516:17)
    at Object.parse (/front-end/Webpack/node_modules/webpack/node_modules/acorn/dist/acorn.js:3098:39)
    at Parser.parse (/front-end/Webpack/node_modules/webpack/lib/Parser.js:902:15)
    at DependenciesBlock.<anonymous> (/front-end/Webpack/node_modules/webpack/lib/NormalModule.js:104:16)
    at DependenciesBlock.onModuleBuild (/front-end/Webpack/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:310:10)
    at nextLoader (/front-end/Webpack/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:275:25)
    at /front-end/Webpack/node_modules/webpack/node_modules/webpack-core/lib/NormalModuleMixin.js:259:5
    at Storage.finished (/front-end/Webpack/node_modules/webpack/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:38:16)
    at /front-end/Webpack/node_modules/webpack/node_modules/enhanced-resolve/node_modules/graceful-fs/graceful-fs.js:78:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
 @ ./app.js 3:0-59

I searched on google but cannot find not a solution for this, can anyone help ?

Thank in advanced

1

1 Answers

2
votes

I had some problems importing bootstrap too, but this solution works for me... Try running the css-loader straight from your entry.js

require("!style!css!./node_modules/bootstrap/dist/css/bootstrap.min.css");

Then I've unchecked it from the webpack.config.js.

Dunno why but running the loader like you did from the config doesn't worked for me neither:

/*
        {
            test: /\.css$/,
            loader: "style-loader!css-loader"
        },
*/