TDD, webpack을 구현하는 학습 프로젝트를 코딩 중입니다.Karma webpack - js에서 CSS 가져 오기를 처리 할 수 없습니다.
나는 다음과 같은 설정으로 웹팩 2를 사용
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
//const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
process.noDeprecation = true;
module.exports = {
entry: './src/js/index.js',
devtool: 'source-map',
context: __dirname,
target: 'web',
stats: 'errors-only',
watch: true,
output: {
path: path.resolve(__dirname, './dist'),
filename: 'js/[name].[chunkHash].js',
publicPath: '/',
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [
path.resolve(__dirname, 'src')
],
exclude: [
path.resolve(__dirname, 'node_modules')
],
loader: 'babel-loader',
options: {
presets: ['es2015']
},
},
{
test: /\.css$/,
/*use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})*/
use: [ 'style-loader', 'css-loader' ]
}
]
},
plugins: [
new WebpackMd5Hash(),
//new ExtractTextPlugin('[name].[contenthash].css'),
new HtmlWebpackPlugin({
template: 'src/index.html',
filename: 'index.html',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
},
inject: true
}),
new webpack.optimize.UglifyJsPlugin()
],
devServer: {
contentBase: path.join(__dirname, "dist/"),
compress: true,
port: 8080
}
}
나는 그것을 컴파일하고 잘 작동 단순히 웹팩 실행합니다. Uncaught Error: Module parse failed: C:\Users\Javid\Desktop\projects\rejection\src\css\style.css Unexpected token (1:0) You may need an appropriate loader to handle this file type.
내가 내 JS 파일에 import '../css/style.css';
를 사용 : 나는 웹팩 전처리와 카르마를 실행하려고하면, 그것은 다음과 같은 오류를 제공합니다. 그것을 많이 봤 거든, 해결책을 찾지 못했습니다.
솔루션
내 CSS를 처리 할 수 additionaly 원시 로더를 사용하고 같이 내 수입을 변경 : import css from 'raw-loader!../css/style.css';
이
try :'use : [{loader : 'style-loade r '}, {loader :'css-loader '}]' –
도움을받지 못했습니다. 나는 문제가 카르마 그 자체와 어떻게 든 관계가 있다고 생각하지만, 무엇을 찾을 수는 없다. Webpack 자체가 정상적으로 실행됩니다. 어쩌면 문제는 karma webpack 전처리기를 사용하는 것입니다. 어떻게 해결해야할지 모르겠습니다. – askerovlab