Skip to content

fix loading css files from node_modules; use new exportOnlyLocals #54

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

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/webpack.client.dev.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const webpack = require('webpack');
const merge = require('webpack-merge');
const path = require('path');
const defaults = require('./webpack.defaults');

const config = merge.smart({
module: {
rules: [{
test: /\.css$/,
include: path.resolve('src'),
use: ['style-loader'],
}, {
test: /\.css$/,
include: path.resolve('node_modules'),
use: ['style-loader'],
}, {
test: /\.scss$/,
Expand Down
6 changes: 6 additions & 0 deletions config/webpack.client.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const merge = require('webpack-merge');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const path = require('path');
const defaults = require('./webpack.defaults');

const config = merge.smart({
module: {
rules: [{
test: /\.css$/,
include: path.resolve('src'),
use: [MiniCSSExtractPlugin.loader],
}, {
test: /\.css$/,
include: path.resolve('node_modules'),
use: [MiniCSSExtractPlugin.loader],
}, {
test: /\.scss$/,
Expand Down
13 changes: 13 additions & 0 deletions config/webpack.defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ module.exports = {
},
{
test: /\.css$/,
include: path.resolve('src'),
use: [
{
loader: 'css-loader',
Expand All @@ -80,6 +81,18 @@ module.exports = {
},
],
},
{
test: /\.css$/,
include: path.resolve('node_modules'),
use: [
{
loader: 'css-loader',
options: {
modules: false,
},
},
],
},
{
test: /\.scss$/,
use: [
Expand Down
4 changes: 2 additions & 2 deletions config/webpack.server.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ module.exports = Object.assign({}, defaults, {
entry: ['webpack/hot/poll?1000'].concat(defaults.entry),
watch: true,
externals: [nodeExternals({
whitelist: ['webpack/hot/poll?1000'],
whitelist: ['webpack/hot/poll?1000', /\.css$/],
Copy link
Contributor Author

@tomconroy tomconroy Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge.smart doesn't seem to handle this nodeExternals, i guess since this thing returns a function. so this is repeated

})],
plugins: defaults.plugins.concat(
new StartServerPlugin('server.js'),
new webpack.HotModuleReplacementPlugin(),
)
),
});
57 changes: 45 additions & 12 deletions config/webpack.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,48 @@ const merge = require('webpack-merge');
const defaults = require('./webpack.defaults.js');
const packageConfig = require('./packageConfig');

module.exports = merge.smart({
module: {
rules: [{
test: /\.css$/,
use: [path.join(__dirname, '../lib/exportLocalsLoader.js')],
}, {
test: /\.scss$/,
use: [path.join(__dirname, '../lib/exportLocalsLoader.js')],
}],
},
}, defaults, {
const config = merge.smart(defaults, {
target: 'node',
mode: 'production',
module: {
rules: [
{
test: /\.css$/,
include: path.resolve('src'),
use: [
{
loader: 'css-loader',
options: {
exportOnlyLocals: true,
},
},
],
},
{
test: /\.css$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these two css tests be merged to one if we pass an array of paths to include?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, we need different config for the node_modules paths. the src paths use our old postcss pipeline as well as modules, so classnames in external packages were transformed to something like .___node_modules____foo-bar-baz

include: path.resolve('node_modules'),
use: [
{
loader: 'css-loader',
options: {
exportOnlyLocals: true,
},
},
],
},
{
test: /\.scss$/,
use: [
{
loader: 'css-loader',
options: {
exportOnlyLocals: true,
},
},
],
},
],
},
node: {
console: false,
global: false,
Expand All @@ -34,7 +63,9 @@ module.exports = merge.smart({
path: path.resolve('build'),
},
// put all node_modules into externals (require() them as usual w/o webpack)
externals: [nodeExternals()],
externals: [nodeExternals({
whitelist: /\.css$/,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this, the node server is trying to require() css files

})],
plugins: [
new webpack.BannerPlugin({
banner: 'require("source-map-support").install();',
Expand All @@ -45,3 +76,5 @@ module.exports = merge.smart({
],
devtool: 'source-map',
});

module.exports = config;
12 changes: 0 additions & 12 deletions lib/exportLocalsLoader.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"chalk": "^2",
"concat-stream": "^1.6.2",
"cross-spawn": "^6",
"css-loader": "^0.28",
"css-loader": "^2",
"enzyme": "^3",
"enzyme-adapter-react-16": "^1.3.0",
"enzyme-to-json": "^3.3",
Expand Down