javascript - Use raw-loader to read css files into strings, but the reading is unsuccessful
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-19 10:11:59
0
2
706

Because the css file needs to be imported, it is processed in the form of a string in js.

Use raw-loader to test and read txt, css, and js files. Only css reading failed. Please solve it. Only the background-color of the body is set in the css file.

import str from 'raw-loader!./style.css';
console.log('read css file-------------------------------------');
console.log(typeof str, str);

Configured in webpack.base.conf.js

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
漂亮男人

webpack configuration

entry:{
        "case7":__dirname+'/index.js',
    },
    output:{
        path: __dirname+'/dist',
        filename:'[name].js',
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: 'raw-loader'
            }
        ]
    }

Import css files into index.js

import txt from './file.css'
console.log(txt);

Run results

伊谢尔伦

Correct answer upstairs

Just import is followed by the css file name, and webpack will automatically use raw-loader to process it according to the suffix name of the file

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template