Storybook only loads stories when I make changes - storybook

Storybook only loads stories when I make changes.
So when I yarn start my storybook it shows up with:
Sorry, but you either have no stories or none are selected somehow.
Please check the Storybook config. Try reloading the page. If the problem persists, check the browser console, or the terminal you've run Storybook from.
When I make a change in one of the *.stories.jsx files it shows all the stories suddenly. I am coming over from storybook in 2015 where everything was previously added as StoriesOf().
The inspection tools in chrome showed:
index.js:49 Unexpected error while loading ./broadcast.stories.jsx: TypeError: Cannot read properties of undefined (reading 'extend')
I am really confused about what type of error this even is. As I said the stories appear once you make any change at all even a space or delete a space somewhere or change a letter and the stories load up.
In side the main.js file I have tried changing: stories: ['../src/stories/**/*.stories.#(js|jsx|ts|tsx)'], into all sorts of suggestions I found on the internet.
const path = require("path");
const resolve = uri => path.resolve(__dirname, uri);
module.exports = {
stories: ['../src/stories/**/*.stories.#(js|jsx|ts|tsx)'],
addons: ['#storybook/addon-docs', '#storybook/addon-knobs', '#storybook/addon-actions', '#storybook/addon-viewport'],
rules: [{
test: /\.(scss|sass)$/,
loaders: ["style-loader", "css-loader", "sass-loader"],
include: path.resolve(__dirname, "../")
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.(woff(2)?|ttf|otf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader?name=fonts/[name].[ext]',
include: path.resolve(__dirname, "../src/fonts")
},
{
test: /\.(jpg|png|svg)$/,
loader: 'url-loader',
options: {
limit: 25000,
}
},
],
watch: true,
resolve: {
alias: {
i18n: resolve('../src/i18n'),
},
extensions: ['.js', '.jsx'],
modules: ['node_modules'],
}
}
An example of a story:
export default {
title: 'ScalableWrapper',
component: ScalableWrapper,
decorators: [],
parameters: {},
}
export const Background = () => <ScalableWrapper style={{ overflow: 'scroll' }}>
<AnimatedBackground
disableAnimationBG={boolean("Disable Animation", false)}
background={text("Background", backgroundImage)}
brushPattern={repeatableBrush}
/></ScalableWrapper>
Package.JSON:
"devDependencies": {
"#babel/cli": "^7.16.0",
"#babel/core": "^7.16.0",
"#babel/plugin-proposal-object-rest-spread": "^7.16.0",
"#babel/plugin-transform-runtime": "^7.16.0",
"#babel/preset-env": "^7.16.0",
"#babel/preset-react": "^7.16.0",
"#storybook/addon-actions": "^6.3.12",
"#storybook/addon-docs": "^6.3.12",
"#storybook/addon-knobs": "^6.3.1",
"#storybook/addon-viewport": "^6.3.12",
"#storybook/react": "^6.3.12",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.3.1",
"babel-loader": "^8.2.3",
"babel-plugin-styled-components": "^1.13.3",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"babel-plugin-transform-react-stateless-component-name": "^1.1.2",
"chai": "^4.3.4",
"css-loader": "^6.5.1",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^6.2.0",
"jest": "^27.3.1",
"jest-enzyme": "^7.1.2",
"node-sass": "^6.0.1",
"postcss-loader": "^6.2.0",
"react-test-renderer": "^17.0.2",
"sass-loader": "^12.3.0",
"storybook-addon-specifications": "^2.2.0",
"style-loader": "^3.3.1",
"webpack": "^5.61.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-dev-middleware": "^5.2.1",
"webpack-dev-server": "^4.4.0"
},
"dependencies": {
"#babel/runtime-corejs3": "^7.16.0",
"chart.js": "^3.6.0",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"path": "^0.12.7",
"prop-types": "^15.7.2",
"react": "^17.0.2",
"react-click-outside": "^3.0.1",
"react-dom": "^17.0.2",
"react-pose": "^4.0.10",
"react-spring": "^9.3.0",
"react-textfit": "^1.1.1",
"styled-components": "^5.3.3",
"styled-tools": "^1.7.2"
},

"chart.js": "^3.6.0",
Chart JS, when it has an error, instead of throwing an error message, sometimes it just silently breaks.
I guess storybook had no handle for this odd case and loaded nothing without an error in the console. Which is fine because storybook was not the one with the error, this seems like Chart's fault.

Related

React bootstrap CSS Unexpected Token

I'm trying to use Bootstrap with a SSR React app. I installed several bootstrap npm packages, but when importing the css into a React component I get an unexpected token error. I made sure that I have css loaders in webpack, and from examples online it doesn't seem like I need to do anything other than importing the css into a component. I'm not sure what I'm doing wrong.
error:
C:\Users\aw030085\OneDrive - Cerner Corporation\Desktop\test2\myssr\node_modules\bootstrap\dist\css\bootstrap.min.css:6
*/:root{--blue:#007bff;--indigo:#6610f2;--purple:#6f42c1;--pink:#e83e8c;--red:#dc3545;--orange:#fd7e14;--yellow:#ffc107;--green:#28a745;--teal:#20c997;--cyan:#17a2b8;--white:#fff;--gray:#6c757d;--gray-dark:#343a40;--primary:#007bff;--secondary:#6c757d;--success:#28a745;--info:#17a2b8;--warning:#ffc107;--danger:#dc3545;--light:#f8f9fa;--dark:#343a40;--breakpoint-xs:0;--breakpoint-sm:576px;--breakpoint-md:768px;--breakpoint-lg:992px;--breakpoint-xl:1200px;--font-family-sans-serif:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";--font-family-monospace:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace}*,::after,::before{box-sizing:border-box}html{font-family:sans-serif;line-height:1.15;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:
SyntaxError: Unexpected token :
at new Script (vm.js:80:7)
at createScript (vm.js:274:10)
at Object.runInThisContext (vm.js:326:10)
at Module._compile (internal/modules/cjs/loader.js:664:28)
at Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Object.newLoader [as .js] (C:\Users\aw030085\OneDrive - Cerner Corporation\Desktop\test2\myssr\node_modules\pirates\lib\index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
package.json dependencies:
"dependencies": {
"bootstrap": "^4.4.1",
"compression": "^1.7.4",
"express": "^4.17.1",
"immer": "^6.0.2",
"prop-types": "^15.7.2",
"react": "^16.12.0",
"react-bootstrap": "^1.0.0",
"react-dom": "^16.12.0",
"react-redux": "^7.2.0",
"react-router-dom": "^5.1.2",
"react-toastify": "^5.5.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"#babel/cli": "^7.8.4",
"#babel/core": "^7.9.0",
"#babel/node": "^7.8.7",
"#babel/plugin-proposal-class-properties": "^7.8.3",
"#babel/plugin-transform-runtime": "^7.9.0",
"#babel/polyfill": "^7.8.7",
"#babel/preset-env": "^7.9.0",
"#babel/preset-react": "^7.9.4",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"css-loader": "^3.4.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.2",
"eslint": "^6.8.0",
"eslint-loader": "^3.0.3",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-react": "^7.19.0",
"jest": "^25.1.0",
"nodemon": "^2.0.2",
"npm-run-all": "^4.1.5",
"serialize-javascript": "^3.0.0",
"style-loader": "^1.1.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11"
}
webpack:
const path = require("path");
const webpack = require('webpack');
module.exports = {
entry: "./src/components/index.js",
output: {
path: path.resolve(__dirname, "public"),
filename: "[name].js"
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"]
},
{
test: /(\.css)$/,
use: ["style-loader", "css-loader"]
}
]
},
resolve: {
extensions: [".js", ".jsx", ".json", ".wasm", ".mjs", "*"]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"development"'
},
}),
]
};
Header.js
import React from 'react';
import { Navbar, Nav} from 'react-bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
const Header = () => {
return (
<>
<Navbar bg="light" variant="light">
<Navbar.Brand href="/">Brand</Navbar.Brand>
<Nav className="mr-auto">
<Nav.Link href="/">Home</Nav.Link>
<Nav.Link href="/world">World</Nav.Link>
</Nav>
</Navbar>
</>
)
}
export default Header;
Also you write you only use css bootstrap.js requires jQuery. So
npm install jquery#latest
might be the step you missed

Cannot find module "popper.js" Angular 5 Visual Studio 2017 asp.net core

I updated my Angular's verision from 4 to 5. Below is the screenshot, I followed the instruction as per the link http://www.talkingdotnet.com/upgrade-angular-4-app-angular-5-visual-studio-2017/
package.json file
{
"name": "VotingWebsite",
"private": true,
"version": "0.0.0",
"scripts": {
"test": "karma start ClientApp/test/karma.conf.js"
},
"devDependencies": {
"#angular/animations": "5.2.1",
"#angular/common": "5.2.1",
"#angular/compiler": "5.2.1",
"#angular/compiler-cli": "5.2.1",
"#angular/core": "5.2.1",
"#angular/forms": "5.2.1",
"#angular/http": "5.2.1",
"#angular/platform-browser": "5.2.1",
"#angular/platform-browser-dynamic": "5.2.1",
"#angular/platform-server": "5.2.1",
"#angular/router": "5.2.1",
"#ngtools/webpack": "1.9.5",
"#types/chai": "4.1.1",
"#types/jasmine": "2.8.5",
"#types/webpack-env": "1.13.3",
"angular2-router-loader": "0.3.5",
"angular2-template-loader": "0.6.2",
"aspnet-prerendering": "^3.0.1",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "3.4.1",
"popper.js": "^1.12.5",
"bootstrap": "4.0.0",
"chai": "4.1.2",
"css": "2.2.1",
"css-loader": "0.28.9",
"es6-shim": "0.35.3",
"event-source-polyfill": "0.0.12",
"expose-loader": "0.7.4",
"extract-text-webpack-plugin": "3.0.2",
"file-loader": "1.1.6",
"html-loader": "0.5.5",
"isomorphic-fetch": "2.2.1",
"jasmine-core": "2.9.1",
"jquery": "3.3.1",
"json-loader": "0.5.7",
"karma": "2.0.0",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-cli": "1.0.1",
"karma-jasmine": "1.1.1",
"karma-webpack": "2.0.9",
"preboot": "6.0.0-beta.1",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.12",
"rxjs": "5.5.6",
"style-loader": "0.19.1",
"to-string-loader": "1.1.5",
"typescript": "2.6.2",
"url-loader": "0.6.2",
"webpack": "3.10.0",
"webpack-hot-middleware": "2.21.0",
"webpack-merge": "4.1.1",
"zone.js": "0.8.20"
}
}
I am getting an error as
Uncaught Error: Cannot find module "popper.js"
at webpackMissingModule (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252)
at vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82252
at Object.<anonymous> (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:82255)
at __webpack_require__ (vendor.js?v=g866IhqI_4JvgibiHgn9GiAXKfG42-s7C9LGGfxA0Tk:sourcemap:21)
at Object.<anonymous> (bootstrap.js from dll-reference vendor_19596f3f8868cecda14a:1)
at __webpack_require__ (bootstrap acba0f7e8b1985fd75ba:678)
at fn (bootstrap acba0f7e8b1985fd75ba:88)
at Object.<anonymous> (process-update.js:146)
at __webpack_require__ (bootstrap acba0f7e8b1985fd75ba:678)
at fn (bootstrap acba0f7e8b1985fd75ba:88)
Webpack.config.js
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const AngularCompilerPlugin = require('#ngtools/webpack').AngularCompilerPlugin;
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
module.exports = (env) => {
// Configuration in common to both client-side and server-side bundles
const isDevBuild = !(env && env.prod);
const sharedConfig = {
stats: { modules: false },
context: __dirname,
resolve: { extensions: [ '.js', '.ts' ] },
output: {
filename: '[name].js',
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix
},
module: {
rules: [
{ test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '#ngtools/webpack' },
{ test: /\.html$/, use: 'html-loader?minimize=false' },
{ test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [new CheckerPlugin()]
};
// Configuration for client-side bundle suitable for running in browsers
const clientBundleOutputDir = './wwwroot/dist';
const clientBundleConfig = merge(sharedConfig, {
entry: { 'main-client': './ClientApp/boot.browser.ts' },
output: { path: path.join(__dirname, clientBundleOutputDir) },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
})
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin(),
new AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'),
exclude: ['./**/*.server.ts']
})
])
});
// Configuration for server-side (prerendering) bundle suitable for running in Node
const serverBundleConfig = merge(sharedConfig, {
resolve: { mainFields: ['main'] },
entry: { 'main-server': './ClientApp/boot.server.ts' },
plugins: [
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./ClientApp/dist/vendor-manifest.json'),
sourceType: 'commonjs2',
name: './vendor'
})
].concat(isDevBuild ? [] : [
// Plugins that apply in production builds only
new AngularCompilerPlugin({
tsConfigPath: './tsconfig.json',
entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'),
exclude: ['./**/*.browser.ts']
})
]),
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, './ClientApp/dist')
},
target: 'node',
devtool: 'inline-source-map'
});
return [clientBundleConfig, serverBundleConfig];
};
It was working perfectly with angular 4 template in asp.net core Visual Studio 2017. When I update the package to Angular 5, I'm getting an error as described above.
I tried to google the solution, but not able to find the solution.
I fixed the same problem in my project by:
1) Adding popper.js to the package.json file (I see you already have this), and running "npm install":
"popper.js": "^1.12.9",
2) Adding an Import popper.js statement to the boot.browser.js file before the import bootstrap statement:
import 'popper.js';
import 'bootstrap';
For newer versions of Angular, npm install #popperjs/core did the trick!
Probably you need to run npm install after you have updated your package.json file.

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-dev-server not applying global styles?

(I'm still new to Angular 5 / Webpack, so I apologize for any misunderstandings!) When I run 'webpack-dev-server', it loads all my styles except for my global style sheet, styles.scss, which contains code that resets the margins and padding to 0. But it's able to load all the other html and css, and can update as I change the code. What's weird though is when I run 'ng serve', the global style sheet applies just fine and the margins and padding are gone!
From what I understand, the loaders are transpiling the scss down to css properly, but for some reason the bundling is getting messed up. Perhaps I'm doing something wrong with how I bundle the files together?? I've messed around with the rules in the config files quite a bit, so I might have accidentally screwed with the interactions between some modules and made the bundling a mess.
I've looked for people who've had similar errors with not being able to get their global styles working on a dev server about a whole day now, but I think I might be looking for the wrong thing. Any help is appreciated!
Below is my webpack config files (webpack.common.js, webpack.dev.js -- the actual webpack.config.js file only contains a one-liner that says it requires webpack.dev.js), my index.html file, my package.json, and a picture of my file tree.
webpack.common.js
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var helpers = require('./helpers');
module.exports = {
entry: {
'polyfills': './src/polyfills.ts',
'vendor': './src/vendor.ts',
'app': './src/main.ts'
},
resolve: {
extensions: ['.ts', '.js']
},
node: {
fs: 'empty'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract("style-loader", "css!sass")
}
],
rules: [
{
test: /\.ts$/,
use: [
{
loader: 'awesome-typescript-loader',
options: { configFileName: helpers.root('tsconfig.json') }
} , 'angular2-template-loader'
],
exclude: [/\.(spec|e2e)\.ts$/]
},
{
test: /\.html$/,
loader: 'raw-loader'
},
{
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file-loader?name=assets/[name].[hash].[ext]'
},
{
test: /\.scss$/,
use: ['to-string-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.json$/,
use: 'json-loader'
}
]
},
plugins: [
// Workaround for angular/angular#11580
new webpack.ContextReplacementPlugin(
// The (\\|\/) piece accounts for path separators in *nix and Windows
/\#angular(\\|\/)core(\\|\/)esm5/,
helpers.root('./src'), // location of your src
{} // a map of your routes
),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html'
}),
new ExtractTextPlugin({
filename: 'style.css',
disable: false,
})
]
};
webpack.dev.js
var webpackMerge = require('webpack-merge');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonConfig = require('./webpack.common.js');
var helpers = require('./helpers');
module.exports = webpackMerge(commonConfig, {
devtool: 'cheap-module-eval-source-map',
output: {
path: helpers.root('dist'),
publicPath: '/',
filename: '[name].js',
chunkFilename: '[id].chunk.js'
},
plugins: [
new ExtractTextPlugin('[name].css')
],
devServer: {
historyApiFallback: true,
stats: 'minimal',
port: 3000
}
});
package.json
{
"name": "project",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "webpack-dev-server --config config/webpack.dev.js --progress --color --hot",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"webpack-dev-server": "webpack-dev-server",
"webpack": "webpack"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.0.1",
"#angular/common": "^5.0.1",
"#angular/compiler": "^5.0.1",
"#angular/core": "^5.0.1",
"#angular/forms": "^5.0.1",
"#angular/http": "^5.0.1",
"#angular/platform-browser": "^5.0.1",
"#angular/platform-browser-dynamic": "^5.0.1",
"#angular/router": "^5.0.1",
"core-js": "^2.5.1",
"es6-shim": "^0.35.3",
"lodash": "^4.17.4",
"rxjs": "^5.5.2",
"ts-loader": "^3.1.1",
"zone.js": "^0.8.14"
},
"devDependencies": {
"#angular/cli": "^1.5.0",
"#angular/compiler-cli": "^5.0.1",
"#angular/language-service": "^5.0.1",
"#types/core-js": "^0.9.43",
"#types/jasmine": "^2.5.54",
"#types/jasminewd2": "~2.0.2",
"#types/node": "^6.0.92",
"#types/webpack": "^3.8.1",
"angular2-template-loader": "^0.6.2",
"awesome-typescript-loader": "^3.3.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"codelyzer": "~3.2.0",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.5",
"html-loader": "^0.5.1",
"html-webpack-plugin": "^2.30.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"raw-loader": "^0.5.1",
"rimraf": "^2.6.2",
"style-loader": "^0.19.0",
"to-string-loader": "^1.1.5",
"ts-node": "^3.2.2",
"tslint": "~5.7.0",
"typescript": "~2.4.2",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4",
"webpack-merge": "^4.1.1"
}
}
file tree
Thank you very much for your help!
Aha! It seems that the issue was I was both using #import in my global stylesheet to include other styles and also using styleUrls in my components. I got rid of styleUrls, kept the #imports in my global stylesheet :)

Webpack --watch doesn't trigger for CSS files in specific directory

Using webpack --watch, changes to .pcss (PostCSS) files are not picked up when within [src/components/Main/]. Changes to .js files are picked up fine as well as .pcss files in other directories. Because my web app is isomorphic, ExtractTextPlugin is used to squish all the CSS together and push it into a single file.
Full code on GitHub.
This is on macOS 10.12.X.
webpack.config.js:
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const babelPresetEnvExclude = require('./config/babel-preset-env.exclude')
const babelPluginRelay = ['relay', { schema: 'data/schema.graphqls', }]
const styleRules = {
test: /\.p?css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: { importLoaders: 1 },
},
'postcss-loader',
],
}),
}
const fileRules = {
test: /\.((pn|sv|jpe?)g|gif)$/,
use: ['file-loader'],
}
const server = {
target: 'node',
entry: './build/unbundled/server.js',
output: {
filename: 'server.js',
path: path.resolve(__dirname, 'build')
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
use: [{
loader: 'babel-loader',
options: {
plugins: [babelPluginRelay],
},
}],
},
styleRules,
fileRules,
]
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
// Overwrites the same file created by the browser webpack config. A loader
// needs to be specified to take care of the import statements and it wont
// work without also outputting a file. There has to be a better way to
// handle this, but I want to focus on other parts for now.
// #todo: make this less bad.
new ExtractTextPlugin('public/main.css'),
]
}
const browser = {
target: 'web',
entry: './build/unbundled/browser.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build/public')
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
use: [{
loader: 'babel-loader',
options: {
presets: [
['env', {
debug: true,
useBuiltIns: true,
targets: { browsers: ['last 2 versions'] },
exclude: babelPresetEnvExclude
}]
],
plugins: [babelPluginRelay],
},
}],
},
styleRules,
fileRules,
]
},
devtool: 'source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
}),
new ExtractTextPlugin('main.css'),
]
}
console.log('NODE_ENV', JSON.stringify(process.env.NODE_ENV || 'development'))
module.exports = [browser, server]
package.json:
{
"name": "rtm-owl",
"version": "1.0.0",
"main": "index.js",
"author": "boring#example.com",
"license": "MIT",
"scripts": {
"relay": "relay-compiler --src ./build/unbundled --schema data/schema.graphqls",
"build": "tsc --pretty && npm run relay && webpack --progress",
"debug": "npm run build && node --inspect build/server.js",
"debug-brk": "npm run build && node --inspect-brk build/server.js",
"start": "node build/server.js",
"watch": "concurrently --kill-others 'tsc --pretty --watch' 'relay-compiler --src ./build/unbundled --schema data/schema.graphqls --watch' 'webpack --watch' 'nodemon build/server.js'"
},
"devDependencies": {
"#types/chart.js": "^2.6.1",
"#types/debug": "^0.0.30",
"#types/express": "^4.0.36",
"#types/fs-extra": "^4.0.0",
"#types/isomorphic-fetch": "^0.0.34",
"#types/lodash": "^4.14.71",
"#types/morgan": "^1.7.32",
"#types/react": "^16.0.0",
"#types/react-chartjs-2": "^2.0.2",
"#types/react-dom": "^15.5.1",
"#types/react-redux": "^4.4.47",
"#types/serialize-javascript": "^1.3.1",
"autoprefixer": "^7.1.2",
"babel-core": "^6.25.0",
"babel-loader": "^7.1.1",
"babel-plugin-relay": "^1.1.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.6.0",
"concurrently": "^3.5.0",
"css-loader": "^0.28.4",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"fs-extra": "^4.0.0",
"isomorphic-fetch": "^2.2.1",
"nodemon": "^1.11.0",
"postcss-css-variables": "^0.7.0",
"postcss-import": "^10.0.0",
"postcss-loader": "^2.0.6",
"postcss-nested": "^2.1.0",
"relay-compiler": "^1.1.0",
"relay-runtime": "^1.1.0",
"serialize-javascript": "^1.3.0",
"style-loader": "^0.18.2",
"typescript": "^2.4.1",
"webpack": "^3.0.0"
},
"dependencies": {
"chart.js": "^2.6.0",
"debug": "^2.6.8",
"express": "^4.15.3",
"farce": "^0.2.1",
"found": "^0.3.1",
"found-relay": "^0.3.0-alpha.4",
"lodash": "^4.17.4",
"morgan": "^1.8.2",
"react": "^15.6.1",
"react-chartjs-2": "^2.5.5",
"react-dom": "^15.6.1",
"react-redux": "^5.0.5",
"react-relay": "^1.0.0",
"redux": "^3.7.2"
}
}
I encountered similar behaviour, webpack --watch does not react to changes in css files on macOS 10.14. I used the basic style-loader and css-loader and require my css files like require('./style.css').
Solved by switching to nodemon. In my package.json the following setup runs webpack whenever js or css files become modified.
...
scripts: {
"build": "webpack",
"watchbuild": "nodemon --watch ./ --ext js,css --ignore dist --exec \"npm run build\"",
...
},
devDependencies: {
"nodemon": "^2.0.4",
"webpack": "^4.39.3",
...
}
...
The setup can be easily customized to watch more file types and to execute a series of commands. For example nodemon --watch ./ --ext js,ejs,css,pcss --ignore dist --exec 'npm run lint && npm run build' will also watch ejs templates and pcss styles and run linter before build.
Note that I had to ignore my build directory dist to prevent infinite build loop. Note also \" instead of ' to provide compatibility between macOS and Windows.

Resources