html - Webpack 包不显示 css

标签 html css django webpack

我之前有一个带 Bootstrap 的 Django 运行良好。我正在尝试使用 Webpack 启动并运行它(没有反应部分): http://owaislone.org/blog/webpack-plus-reactjs-and-django/

捆绑是在我运行 webpack 脚本时创建的。在浏览器中,我一直在获取纯 html,因此未使用该包...

相关代码

测试html.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>This is my fantastic demo!!!</title>
</head>
{% load render_bundle from webpack_loader %}

{% render_bundle 'main' %}
<body>
<div>"how about this?"</div>

</body>
</html>

webpack.config.js:

var path = require('path');
var webpack = require('webpack');`enter code here`
var BundleTracker = require('webpack-bundle-tracker');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var Clean = require('clean-webpack-plugin');
var bootstrapPath = path.join(__dirname, 'node_modules/bootstrap/dist/css');

module.exports = {
    devtool: 'eval-source-map',
    context: __dirname,
    entry: './assets/js/index', // entry point of our app. .assets/js/index.js should require other js modules and dependencies it needs
    output: {
        path: path.resolve('./assets/bundles/'),
        filename: '[name]-[hash].js'
    },
    node: {
        console: true,
        fs: 'empty'
    },
    plugins: [
        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        }),
        new BundleTracker({filename: './webpack-stats.json'}),
        new webpack.BannerPlugin('Banner!!!! todo'),
        new HtmlWebpackPlugin({
            template: __dirname + '/assets/index.tmpl.html'
        }),
        new webpack.HotModuleReplacementPlugin(),
        new Clean(['assets/bundles'])
    ],
    module: {
        loaders: [
            {
                test: /\.js[x]?$/,
                loader: 'babel',
                exclude: /(node_modules|bower-components)/,
                query: {
                    presets: ['es2015', 'stage-0']
                }
            },
            {
                test: /\.json$/,
                loader: 'json-loader'
            },
            {
                test: /\.js$/,
                include: path.resolve(__dirname, 'node_modules/mapbox-gl/js/render/shaders.js'),
                loader: 'transform/cacheable?brfs'
            },
            {
                test: /\.js$/,
                include: path.resolve(__dirname, 'node_modules/webworkify/index.js'),
                loader: 'worker'
            },
            {
                test: /\.css$/,
                loader: 'style!css?modules!postcss'
            },
            {
                test: /\.scss$/,
                loaders: ['style', 'css?sourceMap', 'sass?sourceMap']
            },
            /*
             {
             test: /\.woff$/,
             loader: 'url-loader?limit=10000&mimetype=application/font-woff&name=[path][name].[ext]'
             }, {
             test: /\.woff2$/,
             loader: 'url-loader?limit=10000&mimetype=application/font-woff2&name=[path][name].[ext]'
             }, {
             test: /\.(eot|ttf|svg|gif|png)$/,
             loader: 'file-loader'
             }
             */
            {test: /\.woff(\?v=\d+\.\d+\.\d+)?2?$/, loader: 'url-loader'},
            {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader'},
            {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader'},
            {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader'}
        ]
    },
    postcss: [
        require('autoprefixer')
    ],
    resolve: {
        modulesDirectories: ['node_modules', 'bower_components', bootstrapPath],
        extensions: ['', '.js', '.jsx', '.css'],
        alias: {
            webworkify: 'webworkify-webpack',
            '$': 'jquery',
            'jQuery': 'jquery'
        }
    },
    devServer: {
        contentBase: './assets',
        colors: true,
        historyApiFallback: true,
        inline: true,
        hot: true
    }
};

最佳答案

我正在导入(相当于 ES6 下的 require)一个显然导致问题的插件。将该插件排除在外后,django-webloader-loader 按预期工作。有关详细信息,请参阅: https://github.com/owais/django-webpack-loader/issues/51

关于html - Webpack 包不显示 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35889855/

相关文章:

css - Vaadin ListSelect - 一个列表中的多种样式

DjangoRestFramework - 将 "required = false"添加到 ModelSerializer 字段的正确方法?

javascript - jQuery 将复选框选择转换为数组(未选中时将其设为空)

javascript - jQuery 用户界面 : Increase the padding on resizeable()

javascript - 无法将我的 html 文档连接到 jquery

javascript - 滑动菜单过渡

javascript - 防止div顶部的绝对定位元素阻止div的悬停样式?

html - 将鼠标悬停在按钮上时如何反转按钮渐变

django - 在管理中使用 readonly_fields 在 TextField 中保留格式文本

python - 无法在 MacOS sierra 上使用 pip3 安装 mysqlclient