-
-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 'Local scope' in isomorphics code #59
Comments
You should use webpack to compile your node app, then follow these instructions from the readme:
|
@markdalgleish thanks. I managed to compile my server side with webpack but it takes too long to recompile and run it when I make changes. Right now it feels like it's more reasonable not to use the local scope than use it and wait so long to recompile. Any tips on setting up the environment so it would recompile acceptably faster would be much appreciated. |
On server-side you can put all |
The link you posted gives instructions on how to achieve this. |
@snegostup Can you please post a working example here? I've tried it with
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['babel'],
include: appPath
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css/locals?module&localIdentName=[name]__[local]___[hash:base64:5]!sass'),
include: appPath
}]
}, |
@danielstefanovic Note: For prerendering with extract-text-webpack-plugin you should use css-loader/locals instead of style-loader!css-loader in the prerendering bundle. It doesn't embed CSS but only exports the identifier mappings. This only applies when you do prerender your app. // client bundle without prerendering
{
test: /\.scss$/,
loader: 'style!css?module&localIdentName=[name]__[local]___[hash:base64:5]!sass',
include: appPath
}
// client bundle with prerendering or optimized with separate css
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css?module&localIdentName=[name]__[local]___[hash:base64:5]!sass'),
include: appPath
}
// server bundle for prerendering
{
test: /\.scss$/,
loader: 'css/locals?module&localIdentName=[name]__[local]___[hash:base64:5]!sass',
include: appPath
} |
Thanks for your detailed explanation! It works now. |
I love local css but it's a killer having to compile my node app through webpack. Are there any other options out there? I like how node-jsx allows server side jsx requires. I'm thinking it could be applied to this situation like this.
|
Did anyone integrate this with |
- Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same!
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
* Remove babel and build:node from package.json * Remove include path in babel-loader * Add placeholder to fix fetching data failure if DB does not exist * Modify webpack prod config to compile server-side node - Specify all node_modules files (except binaries) as externals. This means they will be specified as dependencies of the resulting bundle. Read more https://webpack.github.io/docs/configuration.html#externals - Change entry point for server to be server/index.js - Change output path to be /compiled - Remove postcss config - Remove css extraction - Use css-loader/locals in the prerendering bundle to only export identifier mappings webpack-contrib/css-loader#59 (comment) -⚠️ we are keeping context the same so that our css-loader classnames generated remain the same! * Start app with compiled/server.js * Require server.jsx in index.js * Modify express static path to work with webpack * Remove build:prod from scripts in package.json * Change mongo db files to work with webpack - Add index in mongo/models to be used in connect - Remove unneeded default export - Replace fs.readFileSync with a loadModels() function to load the schema * Change sequelize db files to work with webpack * Change none db files to work with webpack * Remove unneeded default export * Modify webpack dev to compile server-side node - Remove babel-node command from package.json - Remove unnecessary files in nodemon.json - Set node_modules as externals in result bundle * Fix webpack dev client to use postcss-loader * Extract externals into common.config - Refactored different paths into output object * Fix incorrect css-loader query parameters - Add (s) to modules - To work with postcss, we need to add importLoaders https://github.com/postcss/postcss-loader#css-modules * Extract postCSSConfig to common.config * Add command line config to webpack in package.json * Bump postcss-loader and postcss-import versions * Add sourcemap support to server-side webpack * Re-add postCSS config into our server-side bundles to prevent warnings * Remove unneeded postcss-simple-vars dependency * Bump postcss-cssnext, postcss-reporter versions - Replace deprecated clearMessages option with clearReportedMessages https://github.com/postcss/postcss-reporter/blob/master/CHANGELOG.md#300 * 2.1.0 * Update Changelog with webpack on server
var styles = require('./index.css')
raises obvious problem -- you can't use<div className={styles.myStyle} >
in a component which renders server-side.Up until now, when requiring css I used
if (__BROWSER__) require('style.css')
but to write<div className={( __BROWSER__ ? styles.myStyle : '')}>
each time I think is too much.This article suggests to use webpack to process backend but it suggests to use
IgnorePlugin(/\.(css|less)$/)
and I believe in case with Local scope won't work.So is there any other option to use Local scope in isomorphic code without any weird hacks?
The text was updated successfully, but these errors were encountered: