Tailwind-CSS doesn't apply flex/block after applying .hidden to the element - css

I want my div to be hidden on small screens and visible on bigger screens starting from md:
But seems like .hidden has a higher priority. Or it just messing up with some of my dependencies.
<div className="hidden md:flex">
I've tried couple of approaches:
Using .block and other display
values instead.
I tried assigning the styles directly from the .css file and giving div a custom container.
Strangely, but some of the properties work fine on responsive changes with md: or lg:
I have a guess it might be something wrong with a bunch of postcss plugins I had to install.
Link to the githhub repo: https://github.com/kkdima/Sweet-Love-And-Roses
Here's my package.json file:
{
"name": "manage-landing-page",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"eslint": "eslint"
},
"dependencies": {
"#next/bundle-analyzer": "^9.5.3",
"#popmotion/popcorn": "^0.4.4",
"#zeit/next-css": "^1.0.1",
"#zeit/next-sass": "^1.0.1",
"atomize": "^1.0.26",
"babel-loader": "^8.0.6",
"eslint-loader": "^4.0.2",
"framer-motion": "^2.6.15",
"next": "^9.5.4",
"next-compose-plugins": "^2.2.0",
"next-images": "^1.5.0",
"next-videos": "^1.4.0",
"node": "^14.13.0",
"node-sass": "^4.14.1",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hamburger-menu": "^1.2.1",
"recompose": "^0.30.0",
"sass": "^1.26.11",
"shopify-buy": "^2.11.0",
"swiper": "^6.3.2"
},
"devDependencies": {
"#babel/plugin-transform-react-jsx": "^7.10.4",
"babel-eslint": "^10.0.3",
"eslint": "^7.9.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-babel": "^9.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-standard": "^4.0.1",
"postcss-flexbugs-fixes": "4.2.1",
"postcss-preset-env": "^6.7.0",
"prettier": "^1.19.1",
"tailwindcss": "^1.8.10"
}
}
Here's my postcss.config.js file:
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('postcss-preset-env')({ stage: 1 }),
require('postcss-flexbugs-fixes'),
],
};
Here's my next.config.js file:
const withPlugins = require('next-compose-plugins');
const withSass = require('#zeit/next-sass');
const withImages = require('next-images');
const withCSS = require('#zeit/next-css');
const withBundleAnalyzer = require('#next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
const withVideos = require('next-videos');
// next.config.js
module.exports = withPlugins([withImages, withSass, withCSS, withVideos], {
plugins: ['postcss-import', 'tailwindcss', 'autoprefixer'],
serverRuntimeConfig: {
// Will only be available on the server side
mySecret: 'secret',
secondSecret: process.env.SECOND_SECRET, // Pass through env variables
},
publicRuntimeConfig: {
// Will be available on both server and client
staticFolder: '/public',
},
module: {
loaders: [
{
test: /.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.(jpe?g|png|gif|woff|woff2|eot|ttf|svg)(\?[a-z0-9=.]+)?$/,
loader: 'url-loader?limit=100000',
},
{
test: /\.(eot|woff|woff2|otf|ttf|svg|png|jpg|gif|webm)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]',
},
},
},
{
test: /\.style.js$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: { importLoaders: 1 },
},
{
loader: 'postcss-loader',
options: { parser: 'sugarss', exec: true },
},
],
},
],
},
webpack(config) {
config.module.rules.push(
{
test: /\.(eot|woff|woff2|otf|ttf|svg|png|jpg|gif)$/,
use: {
loader: 'url-loader',
options: {
limit: 100000,
name: '[name].[ext]',
},
},
},
{
test: /\.style.js$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: { importLoaders: 1 },
},
{
loader: 'postcss-loader',
options: { parser: 'sugarss', exec: true },
},
],
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
},
);
withBundleAnalyzer({});
return config;
},
});

I did this in a native js application. I added this in the terminal:
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
(replace input.css and output.css with your files).
Maybe this gives you an idea as to why its not working in nextjs? For the media query md:flex was not appearing in the dev tools until I started rebuilding the files using this command provided by tailwind.

Related

Modifying localIdentName in css-loader doesn't work in webpack 5 react 17

Currently I am using webpack 5, react 17 and #dr.pogodin/babel-plugin-react-css-modules and all other latest packages.
I am excluding the sass/css files in assets/stylesheets which is being treated as global and using those classes inside className
Styles won't be applied changing localIdentName to something else. Tried getLocalIdent but no use.
Github Repo Link
So how to change the localIdentName ?
package.json
{
"name": "react-app",
"version": "1.0.0",
"description": "React Template App",
"author": "",
"license": "ISC",
"main": "index.js",
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack --mode production"
},
"dependencies": {
"date-fns": "^2.16.1",
"react": "^17.0.1",
"react-dom": "^17.0.1",
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#babel/preset-env": "^7.12.11",
"#babel/preset-react": "^7.12.10",
"#dr.pogodin/babel-plugin-react-css-modules": "^6.0.10",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.2.2",
"css-loader": "^5.0.1",
"html-webpack-plugin": "^5.0.0-beta.1",
"mini-css-extract-plugin": "^1.3.3",
"node-sass": "^5.0.0",
"postcss": "^8.2.1",
"postcss-scss": "^3.0.4",
"sass": "^1.30.0",
"sass-loader": "^10.1.0",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1",
"webpack": "^5.11.0",
"webpack-cli": "^4.3.0",
"webpack-dev-server": "^3.11.0"
}
}
webpack.config.js
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const isDev = process.env.NODE_ENV === "development";
console.log(Environment: ${isDev ? "development" : "production"});
module.exports = {
entry: "./index.js",
mode: isDev ? "development" : "production",
output: {
path: path.join(__dirname, "dist"),
publicPath: "/",
filename: "bundle.js",
},
devServer: {
compress: true,
open: true,
hot: true,
historyApiFallback: true,
quiet: false,
stats: "errors-warnings",
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.(css|sass|scss|less)$/,
use: [
isDev ? "style-loader" : MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
modules: {
auto: (resourcePath) =>
resourcePath.indexOf("assets/stylesheets") === -1,
localIdentName: "[path]___[name]__[local]___[hash:base64:5]",
// getLocalIdent: (context, localIdentName, localName, options) => {
// return "whatever_random_class_name";
// },
},
sourceMap: isDev,
},
},
"sass-loader"
],
}
],
},
plugins: [
new HtmlWebpackPlugin({
template: "./public/index.html",
filename: "./index.html",
favicon: "./public/favicon.ico",
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css",
})
],
devtool: isDev ? "source-map" : false,
};
.babelrc
{
"presets": [
"#babel/preset-env",
"#babel/preset-react"
],
"plugins": [
[
"#dr.pogodin/babel-plugin-react-css-modules",
{
"webpackHotModuleReloading": true,
"autoResolveMultipleImports": true,
"filetypes": {
".scss": {
"syntax": "postcss-scss"
}
}
}
]
]
}
Sounds like I forgot to tell you babel-plugin-react-css-modules has an option to configure the scoped name too which is called generateScopedName.
As long as you configured this as same as css-loader, it should work then:
.babelrc
[
"#dr.pogodin/babel-plugin-react-css-modules",
{
"generateScopedName": "[name]__[local]___[hash:base64:5]", // switch to whatever you want to
// ...
}
]
webpack.config.js:
{
loader: "css-loader",
options: {
modules: {
// ...
localIdentName: "[name]__[local]___[hash:base64:5]",
},
},
},
NOTE: In case of generating based on env, you should use js babel config file babel.config.js so you can conditionally generate the name via NODE_ENV

css file not imported to webpack

I'm trying to implement css modules in my typescript react project, but still can't get the css file imported:
I use css-modules-typescript-loader to create .css.d.ts to assert typing
I use #dr.pogodin/react-css-modules to be able to use css modules ("styleName") in react. It'll generate some hash for the css property like the "src-containers-___App__background___2WjSL" in the image above
Here are the files regarding the App and css:
App.tsx:
import "./App.css";
//returns some jsx
<h3 styleName="background" className="background">CSS Here</h3>
//I also use react className to hope the css renders
App.css:
.background {
color: pink;
background-color: black;
font-size: 20px;
}
App.css.d.ts:
interface CssExports {
'background': string;
}
export const cssExports: CssExports;
export default cssExports;
And Here are the configs, where I think the problem comes from:
webpack.config.ts:
import * as path from "path";
import * as webpack from "webpack";
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const config: webpack.Configuration = {
entry: "./src/index.tsx",
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-typescript",
],
},
},
},
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-modules-typescript-loader" },
{
loader: "css-loader",
options: {
modules: true,
},
},
// {
// loader: "postcss-loader",
// options: {
// postcssOptions: {
// plugins: [
// [
// "postcss-preset-env",
// {
// // Options
// },
// ],
// ],
// },
// },
// },
// I don't know how they should be chained and what loader/options exactly to include
],
},
],
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
output: {
path: path.resolve(__dirname, "build"),
filename: "bundle.js",
},
devServer: {
contentBase: path.join(__dirname, "build"),
compress: true,
port: 4000,
},
plugins: [
new ForkTsCheckerWebpackPlugin({
async: false,
eslint: {
files: "./src/**/*",
},
}),
],
};
export default config;
.babelrc:
{
"presets": [
"#babel/preset-env",
"#babel/preset-react",
"#babel/preset-typescript"
],
"plugins": [
["#dr.pogodin/react-css-modules", {
"webpackHotModuleReloading": true
}],
[
"#babel/plugin-transform-runtime",
{
"regenerator": true
}
],
]
}
If helpful:
tsconfig.json:
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}
package.json:
"dependencies": {
"#dr.pogodin/babel-plugin-react-css-modules": "^6.0.7",
"react": "^16.14.0",
"react-dom": "^16.14.0"
},
"devDependencies": {
"#babel/core": "^7.12.3",
"#babel/plugin-transform-runtime": "^7.12.1",
"#babel/preset-env": "^7.12.1",
"#babel/preset-react": "^7.12.5",
"#babel/preset-typescript": "^7.12.1",
"#babel/runtime": "^7.12.5",
"#teamsupercell/typings-for-css-modules-loader": "^2.4.0",
"#testing-library/dom": "^7.26.5",
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/react": "^11.1.1",
"#testing-library/user-event": "^12.2.0",
"#types/fork-ts-checker-webpack-plugin": "^0.4.5",
"#types/jest": "^26.0.15",
"#types/react": "^16.9.55",
"#types/react-dom": "^16.9.9",
"#types/webpack": "^4.41.24",
"#types/webpack-dev-server": "^3.11.1",
"#typescript-eslint/eslint-plugin": "^4.6.1",
"#typescript-eslint/parser": "^4.6.1",
"babel-jest": "^26.6.3",
"babel-loader": "^8.1.0",
"babel-plugin-react-css-modules": "^5.2.6",
"css-loader": "^5.0.1",
"css-modules-typescript-loader": "^4.0.1",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"fork-ts-checker-webpack-plugin": "^5.2.1",
"jest": "^26.6.3",
"postcss": "^8.1.6",
"postcss-loader": "^4.0.4",
"precss": "^4.0.0",
"prettier": "2.1.2",
"react-test-renderer": "^17.0.1",
"style-loader": "^2.0.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.5",
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
}
Any hint would be helpful, thanks!
The problem here is the generated hash name between babel-plugin-react-css-modules vs css-loader are now different in pattern.
In order to fix this, since babel-plugin-react-css-modules is now using this pattern [path]___[name]__[local]___[hash:base64:5] by default, you just fix by configure css-loader using the same pattern as following:
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[path]___[name]__[local]___[hash:base64:5]',
},
}
}

Webpack 4 - Minify CSS that was compiled from SCSS

Developing a wordpress site and using webpack to bundle assets.
I have a setup where I'm compiling SCSS to CSS among other things. I want to minify the output CSS and remove comments. I tried to add optimize-css-assets-webpack-plugin and configure it as example suggests, but it doesn't work (no errors)...
So how can I modify this webpack config so that output is (1) stripped of comments and (2) minified?
webpack.config.js:
const path = require("path");
const config = require('./config.js');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
mode: 'production',
entry: ["./src/app.js", "./src/scss/style.scss"],
output: {
path: path.resolve(__dirname, "wp-content/themes/ezdigital"),
filename: "js/[name].js"
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].css"
}
},
{
loader: "extract-loader"
},
{
loader: "css-loader?-url"
},
{
loader: "postcss-loader"
},
{
loader: "sass-loader"
}
]
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["env"]
}
}
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"]
}
]
},
//remove comments from JS files
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false,
},
},
}),
],
},
plugins: [
new BrowserSyncPlugin( {
proxy: config.url,
files: [
'**/*.php'
],
reloadDelay: 0
}
)
]
};
additional postss.config.js:
module.exports = {
plugins: {
'autoprefixer': {}
}
}
Package.json:
{
"name": "EZTheme",
"version": "1.0.0",
"description": "EZ Theme",
"main": "index.js",
"scripts": {
"test": "test",
"build": "webpack",
"start": "webpack --watch",
"serve": "webpack-dev-server --open"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": ""
"devDependencies": {
"#fortawesome/fontawesome-free": "^5.6.3",
"autoprefixer": "^9.3.1",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"browser-sync-webpack-plugin": "^2.2.2",
"css-loader": "^1.0.1",
"exports-loader": "^0.7.0",
"extract-loader": "^3.1.0",
"extract-text-webpack-plugin": "^4.0.0-alpha.0",
"file-loader": "^2.0.0",
"jquery": "^3.3.1",
"node-sass": "^4.11.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"popper.js": "^1.14.6",
"postcss-cli": "^6.0.1",
"postcss-loader": "^3.0.0",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"uglifyjs-webpack-plugin": "^2.1.1",
"webpack": "^4.28.2",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.14"
},
"dependencies": {
"bootstrap": "^4.1.3"
}
}
It turns out the problem was that I was trying to use extract-text-webpack-plugin which does not work with webpack 4.
Instead, I switched to mini-css-extract-plugin along with optimize-css-assets-webpack-plugin.
My new webpack.config.js file:
const path = require("path");
const config = require('./config.js');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = {
mode: 'production',
entry: ["./src/app.js", "./src/scss/style.scss"],
output: {
path: path.resolve(__dirname, "wp-content/themes/ezdigital"),
filename: "js/[name].js"
},
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].css"
}
},
{
loader: "extract-loader"
},
{
loader: "css-loader?-url"
},
{
loader: "postcss-loader"
},
{
loader: "sass-loader"
}
]
},
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["env"]
}
}
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"]
}
]
},
//remove comments from JS files
optimization: {
minimizer: [
new UglifyJsPlugin({
uglifyOptions: {
output: {
comments: false,
},
},
}),
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }],
}
})
],
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css"
}),
new BrowserSyncPlugin( {
proxy: config.url,
files: [
'**/*.php'
],
reloadDelay: 0
}
)
]
};

Page styles break when I change styles in Chrome DevTools with Webpack HMR

I have a strange problem:
I'm using Webpack (with Vue-CLI) + HMR.
When I try to change styles in the browser in DevTools, then my page itself changes the styles - it removes some of them (screenshots below).
I understand that the problem is in the Hot Reload Webpack, because some Vue-Components styles remain, and some are deleted. So I can not change the styles in the sidebar and I have to reload the page every time to get the styles back in place.
Below is added my package.json and webpack.base.conf.js.
Thank you in advance!
P.S. Also I use SASS with SASS-Loader.
package.json
{
"private": true,
"scripts": {
"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
"start": "npm run dev",
"build": "node build/build.js"
},
"dependencies": {
"bootstrap": "^4.0.0",
"desandro-classie": "^1.0.1",
"desandro-get-style-property": "^1.0.4",
"draggabilly": "^2.1.1",
"jquery": "^3.2.1",
"jquery-parallax.js": "^1.5.0",
"popper.js": "^1.12.9",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
"babel-core": "^6.22.1",
"babel-helper-vue-jsx-merge-props": "^2.0.3",
"babel-loader": "^7.1.1",
"babel-plugin-syntax-jsx": "^6.18.0",
"babel-plugin-transform-runtime": "^6.22.0",
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
"html-webpack-plugin": "^2.30.1",
"imports-loader": "^0.7.1",
"modernizr-webpack-plugin": "^1.0.6",
"node-notifier": "^5.1.2",
"node-sass": "^4.7.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"ora": "^1.2.0",
"portfinder": "^1.0.13",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"rimraf": "^2.6.0",
"sass-loader": "^6.0.6",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
"uglifyjs-webpack-plugin": "^1.1.1",
"url-loader": "^0.5.8",
"vue-loader": "^13.3.0",
"vue-style-loader": "^3.0.1",
"vue-template-compiler": "^2.5.2",
"webpack": "^3.6.0",
"webpack-bundle-analyzer": "^2.9.0",
"webpack-dev-server": "^2.9.1",
"webpack-merge": "^4.1.0"
},
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
webpack.base.conf.js
'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')
const ModernizrWebpackPlugin = require('modernizr-webpack-plugin')
const webpack = require('webpack')
let modernizrConfig = {
"options": [
"prefixed",
// "prefixedCSS",
// "testStyles",
"testAllProps",
"testProp",
"html5shiv",
"domPrefixes"
]
}
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports = {
context: path.resolve(__dirname, '../'),
entry: {
app: './src/main.js'
},
output: {
path: config.build.assetsRoot,
filename: '[name].js',
publicPath: process.env.NODE_ENV === 'production'
? config.build.assetsPublicPath
: config.dev.assetsPublicPath
},
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'#': resolve('src'),
}
},
module: {
rules: [
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]')
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
}
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
},
{
test: /[\/\\]node_modules[\/\\]some-module[\/\\]index\.js$/,
loader: "imports-loader?this=>window"
}
]
},
plugins: [
new ModernizrWebpackPlugin(modernizrConfig),
new webpack.ProvidePlugin({
Draggabilly: 'draggabilly',
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
node: {
// prevent webpack from injecting useless setImmediate polyfill because Vue
// source contains it (although only uses it if it's native).
setImmediate: false,
// prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client
dgram: 'empty',
fs: 'empty',
net: 'empty',
tls: 'empty',
child_process: 'empty'
}
}
One way to fix this is setting sourceMap to false for the sass loaderOptions in vue.config.js:
css: {
loaderOptions: {
scss: {
sourceMap: false
}
}
}
I have the same problem with NUXT project. reinstall of sass-loader / sass in the last version was solve the problem.

Webpack - ExtractTextPlugin : No css file generated, no error

I am trying to use the https://github.com/webpack-contrib/extract-text-webpack-plugin in order to get a mixed css file.
With my current situation, I have this :
As you can see, I have my js file, my fonts but no sign of css file ...
I tried several examples I found on their github issue or their documentation but still no result.
My package.json :
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server --env=dev --progress --watch --content-base src/app"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.4.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"css-loader": "^0.28.1",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.11.1",
"json-loader": "^0.5.4",
"postcss-cssnext": "^2.10.0",
"postcss-loader": "^2.0.1",
"postcss-modules-values": "^1.2.2",
"raw-loader": "^0.5.1",
"sass-loader": "^6.0.3",
"style-loader": "^0.17.0",
"url-loader": "^0.5.8",
"webpack": "^2.5.1",
"webpack-dev-server": "^2.4.5"
},
"dependencies": {
"admin-lte": "git://github.com/almasaeed2010/AdminLTE.git#37c8bbb01998db487382e9d62cfb398511167f3a",
"bootstrap-daterangepicker": "git://github.com/dangrossman/bootstrap-daterangepicker.git#29bbf5a04df69fda363cedb534272ac344524e57",
"bootstrap-table": "^1.11.2",
"eonasdan-bootstrap-datetimepicker": "git://github.com/Eonasdan/bootstrap-datetimepicker.git#4.17.47",
"font-awesome": "^4.7.0",
"ionicons": "^3.0.0",
"jquery": "^3.2.1",
"jquery-confirm": "git://github.com/craftpip/jquery-confirm.git",
"lobibox": "git://github.com/arboshiki/lobibox.git",
"lodash": "^4.17.4",
"moment-timezone": "^0.5.13",
"parsleyjs": "^2.7.1",
"push.js": "0.0.13",
"socket.io-client": "^1.7.4",
"tableexport.jquery.plugin": "git://github.com/hhurz/tableExport.jquery.plugin.git"
}
}
My webpack.config.js :
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const postcssPlugins = [
require('postcss-cssnext')(),
require('postcss-modules-values')
];
const scssLoader = [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'sass-loader' }
];
const postcssLoader = [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { modules: true } },
{ loader: 'postcss-loader', options: { plugins: () => [...postcssPlugins] } }
];
// you'll need to npm install the following: [raw-loader, html-minifier-loader, json-loader, css-loader,style-loader, url-loader, file-loader ]
// in your index.html you should have two script tags, one for app.js(or bundle.js) and vendor.js
// no need for babelify with webpack. just, npm install --save-dev babel-cli babel-preset-es2016
// in .babelrc file change the preset of 2015 to ["es2016"]
module.exports = {
entry: {
app: './app.js',
// if any on these are just for css remove them from here and require(with absolute path) them from app.js
vendor: [
'babel-polyfill',
'admin-lte',
'admin-lte/bootstrap/js/bootstrap.min.js',
'lobibox/dist/js/notifications.min.js',
'admin-lte/plugins/fastclick/fastclick.js',
'moment',
'moment/locale/fr.js',
'moment-timezone',
'eonasdan-bootstrap-datetimepicker',
'bootstrap-table',
'bootstrap-table/dist/locale/bootstrap-table-fr-BE.min.js',
'parsleyjs',
'parsleyjs/dist/i18n/fr.js',
'bootstrap-daterangepicker',
'socket.io-client',
'jquery-confirm',
'push.js',
'lodash',
'bootstrap-table/dist/extensions/export/bootstrap-table-export.min.js',
'tableexport.jquery.plugin'
]
},
//devtool: 'eval', // for test in the browser
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')//,
//pathinfo: true
},
module: {
rules: [{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.html$/,
use: ['raw-loader', 'html-minifier-loader'],
exclude: /node_modules/
}, {
test: /\.json$/,
use: 'json-loader',
exclude: /node_modules/
}, {
test: /\.(scss|sass)$/,
loader: ExtractTextPlugin.extract(scssLoader),
include: [__dirname]
},{
test: /\.css$/,
loader: postcssLoader,
include: [__dirname]
}, {
test: /\.(jpg|png|gif)$/,
use: 'file-loader'
}, {
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader?name=fonts/[name].[ext]'
}],
},
plugins: [
new ExtractTextPlugin("app.bundle.css"),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
],
};
My app.js (only several require and a console.log for test) :
console.log("coucou");
require('admin-lte/dist/css/skins/skin-blue.min.css');
require('admin-lte/dist/css/AdminLTE.min.css');
require('jquery-confirm/dist/jquery-confirm.min.css');
require('bootstrap-table/dist/bootstrap-table.min.css');
require('bootstrap-daterangepicker/daterangepicker.css');
require('eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css');
require('admin-lte/plugins/select2/select2.min.css');
require('lobibox/dist/css/lobibox.min.css');
require('ionicons/dist/css/ionicons.min.css');
require('font-awesome/css/font-awesome.min.css');
require('admin-lte/bootstrap/css/bootstrap.min.css');
There is a typo in the documentation. I think the problem is the definition on plugings. Try that:
new ExtractTextPlugin({
filename: 'app.bundle.css',
allChunks: true
}),

Resources