javascript - webpack css loader 不工作 : no output css file

标签 javascript css webpack

我正在从事开源元素,现在我需要为前端设置 webpack。我在下面尝试了 webpack 配置,JS 工作正常,但 css 不行,没有 css 输出文件。我不知道为什么会这样,请帮助我。

下面是我的 webpack 配置 js 文件:

const path = require("path");
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

const node_dir = __dirname + '/node_modules';

const sassLoaders = [
  'css-loader',
  'sass-loader?indentedSyntax=sass&includePaths[]=' + path.resolve(__dirname, './public/stylesheets/')
]

const config = {
    addVendor: function (name, path) {
        this.resolve.alias[name] = path;
        this.module.noParse.push(new RegExp('^' + name + '$'));
    },

    entry: {
        app: './public/javascripts/app.js',
    vendors: ['jquery','underscore']
    },

    output: {
        path: path.join(__dirname, process.env.NODE_ENV === 'production' ? './public/dist' : './public/dev'),
        filename: process.env.NODE_ENV === 'production' ? '[name].[hash].js' : '[name].js',
        publicPath: 'public/dev'
    },

    module:{
        noParse: [],
        loaders:[
            {
                test: /\.scss$/,
                loader: ExtractTextPlugin.extract('style-loader', sassLoaders.join('!'))
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader:'babel?presets[]=es2015'
            }
        ]
    },

    resolve: {
        alias: {},
        extensions: ['', '.js', '.scss'],
    },

    plugins: [
        new webpack.NoErrorsPlugin(),
        new ExtractTextPlugin("qor.css", {
            allChunks: true
        }),
        new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.bundle.js'),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery"
        }),
        new webpack.ProvidePlugin({
          _: "underscore",
        })
    ]
};

config.addVendor('jquery', node_dir + '/jquery/dist/jquery.js');
config.addVendor('underscore', node_dir + '/underscore/underscore.js');

module.exports = config;

当我运行 webpack -d --watch --progress --colors 时,没有 css 文件输出。只是 js 文件。

enter image description here

这是我的元素文件夹

enter image description here

最佳答案

你没有忘记使用 require 在 js 入口点要求你的样式表吗:

// in your modules just require the stylesheet
// This has the side effect that a <style>-tag is added to the DOM.
require("./stylesheet.css");

如果你想生成一个原生的 css 输出文件,查看 this guide from webpack documentation .

关于javascript - webpack css loader 不工作 : no output css file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36146819/

相关文章:

typescript - webpack TS2304 找不到名称 'Map'、 'Set'、 'Promise'

angular - [at-loader] node_modules\@types\jasmine 中的错误

javascript - 使用参数解构时是否可以检查无效参数?

javascript - 接收参数并在不做任何修改的情况下返回它的函数

css - 在浏览器中编辑时保留 css

html - 文本输入和按钮对齐

javascript - 不使用键名获取关联数组的值

javascript - Node.js 性能 - 读取文件一次或每次请求时读取文件

android - 在另一个布局上设置布局

angular - 升级到 angular 5 后 webpack 命令失败