Question: Does brunch support npm packages with css modules?
See original GitHub issueDescription
Sample repo: https://github.com/tony-g/brunch-npm-cssmodules
I’m trying to use an npm module that imports its own bundled css modules. e.g.
/* their-module/css/styles.css */
.some-styles {
color: red;
}
/* their-module/js/app.js */
import '../css/styles.css';
I turned on css modules in the brunch config (see config below or in the sample repo).
Expected behavior
Would be nice if brunch require.register
’d [npm-package]/css/styles.css
with the css modules info.
Actual behavior
- brunch is appending
module.exports = { [cssModulesInfo ... ]}
- but it’s not wrapping it in
require.register
- so
module
isn’t defined when the statement executes, and you get js errors.
I was thinking about working around it with a plugin - the plugin has the file path so I could conditionally wrap npm packages styles in require.register
- but I’m not super familiar with the brunch internals so I wasn’t sure just how bad of an idea that was! 😃
Environment
- Brunch: 2.8.2
- Node: 4.4.7
- NPM: 3.3.6
- Operating system: OSX 10.11.6
package.json
contents
{
"name": "brunch-app",
"description": "Description",
"author": "Your Name",
"version": "0.1.0",
"repository": {
"type": "git",
"url": ""
},
"scripts": {
"start": "brunch watch --server",
"build": "brunch build --production"
},
"dependencies": {
"react": "^15.3.0",
"react-redux": "^4.4.5",
"redux": "^3.5.2",
"redux-notifications": "^2.1.1"
},
"devDependencies": {
"auto-reload-brunch": "^2.0.0",
"babel-brunch": "^6.0.5",
"babel-preset-react": "^6.11.1",
"brunch": "^2.8.2",
"clean-css-brunch": "^2.0.0",
"css-brunch": "../css-brunch",
"javascript-brunch": "^2.0.0"
}
}
brunch config contents
module.exports = {
// See http://brunch.io for documentation.
files: {
javascripts: {joinTo: 'app.js'},
stylesheets: {joinTo: 'app.css'},
templates: {joinTo: 'app.js'}
},
plugins: {
babel: {
presets: ['es2015', 'es2016', 'react']
},
css: {
modules: true
}
}
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
import vendor css? · Issue #1669 · brunch/brunch - GitHub
I'm using brunch to process a css file provided in one of the node modules my project depends on. (Specifically, vue-material).
Read more >Using JS modules and NPM - Brunch.io
Organizing your JS code by modules is a central idea in Brunch. It allows your files to each have a separate scope, and...
Read more >brunch - npm
Fast front-end web app build tool with simple declarative config and seamless incremental compilation for rapid development.
Read more >Build npm dependency's sources with Brunch - Stack Overflow
I've been trying to build my web application with Brunch. It depends on a certain npm package (animated-vue), which only contains sources and ......
Read more >Js libraries - global variables - brunch-config - Elixir Forum
I only mentioned “CSS Modules” because you are bound to come across examples where CSS is imported into JS. Brunch itself doesn't support...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No support for now.
I was struggling with this as well. The thing that fixed it for me was realizing (mostly accidentally, but with some help from this: https://gist.github.com/taiansu/c68e7aefe8163637998acdf532d15da4), that the npm.styles paths seem to be relative to the node_modules/<package>/ directory, not to node_modules/ like the globals seem to be?:
I hope it helps someone.