Skip to content

Commit b381bf1

Browse files
committed
fix: fix _document.js crash
1 parent 9e6bc3b commit b381bf1

File tree

4 files changed

+144
-104
lines changed

4 files changed

+144
-104
lines changed

css-loader-config.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');
2-
const findUp = require('find-up');
1+
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin')
2+
const findUp = require('find-up')
33

4-
const fileExtensions = new Set();
5-
let extractCssInitialized = false;
4+
const fileExtensions = new Set()
5+
let extractCssInitialized = false
66

77
module.exports = (
88
config,
@@ -18,7 +18,7 @@ module.exports = (
1818
) => {
1919
// We have to keep a list of extensions for the splitchunk config
2020
for (const extension of extensions) {
21-
fileExtensions.add(extension);
21+
fileExtensions.add(extension)
2222
}
2323

2424
if (!isServer) {
@@ -27,7 +27,7 @@ module.exports = (
2727
test: new RegExp(`\\.+(${[...fileExtensions].join('|')})$`),
2828
chunks: 'all',
2929
enforce: true
30-
};
30+
}
3131
}
3232

3333
if (!isServer && !extractCssInitialized) {
@@ -44,37 +44,37 @@ module.exports = (
4444
orderWarning: false,
4545
reloadAll: true
4646
})
47-
);
48-
extractCssInitialized = true;
47+
)
48+
extractCssInitialized = true
4949
}
5050

5151
if (!dev) {
5252
if (!Array.isArray(config.optimization.minimizer)) {
53-
config.optimization.minimizer = [];
53+
config.optimization.minimizer = []
5454
}
5555
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin');
56-
config.optimization.minimizer.push(new OptimizeCssAssetsWebpackPlugin({}));
56+
config.optimization.minimizer.push(new OptimizeCssAssetsWebpackPlugin({}))
5757
}
5858

5959
const postcssConfig = findUp.sync('postcss.config.js', {
6060
cwd: config.context
61-
});
62-
let postcssLoader;
61+
})
62+
let postcssLoader
6363

6464
if (postcssConfig) {
6565
// Copy the postcss-loader config options first.
6666
const postcssOptionsConfig = Object.assign(
6767
{},
6868
postcssLoaderOptions.config,
6969
{ path: postcssConfig }
70-
);
70+
)
7171

7272
postcssLoader = {
7373
loader: 'postcss-loader',
7474
options: Object.assign({}, postcssLoaderOptions, {
7575
config: postcssOptionsConfig
7676
})
77-
};
77+
}
7878
}
7979

8080
const cssLoader = {
@@ -91,16 +91,16 @@ module.exports = (
9191
},
9292
cssLoaderOptions
9393
)
94-
};
94+
}
9595

9696
// When not using css modules we don't transpile on the server
9797
if (isServer && !cssLoader.options.modules) {
98-
return ['ignore-loader'];
98+
return ['ignore-loader']
9999
}
100100

101101
// When on the server and using css modules we transpile the css
102102
if (isServer && cssLoader.options.modules) {
103-
return [cssLoader, postcssLoader, ...loaders].filter(Boolean);
103+
return [cssLoader, postcssLoader, ...loaders].filter(Boolean)
104104
}
105105

106106
return [
@@ -109,5 +109,5 @@ module.exports = (
109109
cssLoader,
110110
postcssLoader,
111111
...loaders
112-
].filter(Boolean);
113-
};
112+
].filter(Boolean)
113+
}

index.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
const cssLoaderConfig = require('./css-loader-config');
1+
const cssLoaderConfig = require('./css-loader-config')
22

33
module.exports = (nextConfig = {}) => {
44
return Object.assign({}, nextConfig, {
55
webpack(config, options) {
66
if (!options.defaultLoaders) {
77
throw new Error(
8-
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
9-
);
8+
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade',
9+
)
1010
}
1111

12-
const { dev, isServer } = options;
13-
const { cssModules, cssLoaderOptions, postcssLoaderOptions } = nextConfig;
12+
const { dev, isServer } = options
13+
const { cssLoaderOptions, postcssLoaderOptions } = nextConfig
1414

1515
const createStyleConfig = cssModules =>
1616
(options.defaultLoaders.css = cssLoaderConfig(config, {
@@ -19,35 +19,35 @@ module.exports = (nextConfig = {}) => {
1919
cssLoaderOptions,
2020
postcssLoaderOptions,
2121
dev,
22-
isServer
23-
}));
22+
isServer,
23+
}))
2424

2525
config.module.rules.push({
2626
test: /\.css$/,
2727
oneOf: [
2828
{
2929
resourceQuery: /CSSModulesDisable/,
30-
use: createStyleConfig(false)
30+
use: createStyleConfig(false),
3131
},
3232
{
33-
use: createStyleConfig(true)
34-
}
33+
use: createStyleConfig(true),
34+
},
3535
],
3636
issuer(issuer) {
3737
if (issuer.match(/pages[\\/]_document\.js$/)) {
3838
throw new Error(
39-
'You can not import CSS files in pages/_document.js, use pages/_app.js instead.'
40-
);
39+
'You can not import CSS files in pages/_document.js, use pages/_app.js instead.',
40+
)
4141
}
42-
return true;
43-
}
44-
});
42+
return true
43+
},
44+
})
4545

4646
if (typeof nextConfig.webpack === 'function') {
47-
return nextConfig.webpack(config, options);
47+
return nextConfig.webpack(config, options)
4848
}
4949

50-
return config;
51-
}
52-
});
53-
};
50+
return config
51+
},
52+
})
53+
}

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
"version": "2.1.7",
44
"main": "index.js",
55
"license": "MIT",
6-
"repository": "uncleseneca/next-css",
6+
"repository": "next-css-unpluggable",
77
"scripts": {
88
"release": "standard-version"
99
},
1010
"dependencies": {
11-
"css-loader": "^2.1.0",
12-
"extract-css-chunks-webpack-plugin": "^3.3.2",
11+
"css-loader": "1.0.0",
12+
"extract-css-chunks-webpack-plugin": "^3.2.0",
1313
"extracted-loader": "1.0.4",
14-
"find-up": "3.0.0",
14+
"find-up": "2.1.0",
15+
"ignore-loader": "0.1.2",
1516
"optimize-css-assets-webpack-plugin": "^5.0.1",
1617
"postcss-loader": "3.0.0"
1718
},

0 commit comments

Comments
 (0)