Hello,
I have been struggling with webpack since month for now, i am new to webpack so i have couple of questions.
I have a perfect output with the things i need, i can extract css flies, multiple css to 1 file etc. All is working good.
but what i cant do is below !
I am doing this to care of performace insigths according to PageSpeed. so that.
I have two css files, one for entire styling and the other one for basic style drawing to inline in html.
since i can extract css as a file, i cant inline it in same build and the reverse as same, i cant extract css file if i inlined it.
I want to extract a.css as file extracted, and b.css as inlined
I tried to use loader multiple times but not worked ?
Looking forward here something helps me with this.
var path = require('path');
var webpack = require("webpack");
var $ = require("jquery");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
const PreloadWebpackPlugin = require('preload-webpack-plugin');
module.exports = {
entry: {
a: ["./src/kk.js"]
},
output: {
filename: 'app.bundle.js',
path: path.resolve(__dirname, './public/'),
publicPath: "",
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
},
{
test: /\.(jpe?g|png|gif|jpg|svg)$/i, //to support eg. background-image property
use: [
'file-loader?name=[name].[ext]&outputPath=images/&publicPath=/',
'image-webpack-loader'
]
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/, //to support @font-face rule
loader: "url-loader",
query:{
limit:'10000',
name:'[name].[ext]',
outputPath:'fonts/'
}
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
},
{
test: /font-awesome\.config\.js/,
use: [
{ loader: "style-loader" },
{ loader: "font-awesome-loader" }
]
}
]
},
resolve: {
alias: {
jquery: "jquery/src/jquery"
}
},
plugins: [
new ExtractTextPlugin({
filename: 'bundle.css',
disable: false,
allChunks: true
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'src/index.html',
minify: {
collapseWhitespace: false
}
}),
new PreloadWebpackPlugin({
rel: 'preload',
as: 'script',
include: ['a']
}),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new webpack.optimize.UglifyJsPlugin()
]
}
webpack.config.js
{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ],
include: new Regex('/path/to/inline/styles/') // <=
}
webpack.config.js
{
test: /\.css$\,
use: ExtractTextPLugin.extract({
fallback: 'style-loader',
use: [ 'css-loader' ]
}),
exclude: new Regex('path/to/inline/styles') // <=
}
@michael-ciniawsky # Thank you!
Most helpful comment
@michael-ciniawsky # Thank you!