This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
117 lines (110 loc) · 2.82 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const runtimeDotenv = require('next-runtime-dotenv')
const cssLoaderConfig = require('@zeit/next-css/css-loader-config')
const autoprefixer = require('autoprefixer')
const path = require('path')
const withDotenv = runtimeDotenv({
public: [
'PORT',
'API_URL',
],
server: [
// SSR only
],
})
const localStyleCondition = [
path.join(__dirname, 'containers'),
path.join(__dirname, 'components'),
path.join(__dirname, 'pages'),
]
function getStyleLoaders(format, mode, config, { dev, isServer }) {
return cssLoaderConfig(config, {
extensions: [format],
cssModules: mode === 'local',
cssLoaderOptions: {
// importLoaders: 2,
// url: false,
},
dev,
isServer,
loaders: [
{
loader: 'postcss-loader',
options: {
plugins: () => [
autoprefixer({ browsers: ['last 2 versions'] }),
],
},
},
{
loader: 'resolve-url-loader',
options: {},
},
...(format === 'scss' ? [
{
loader: 'sass-loader',
options: {
sourceMap: true, // needed by resolve-url-loader
},
},
{
loader: 'sass-resources-loader',
options: {
sourceMap: true, // needed by resolve-url-loader
resources: [
path.resolve(__dirname, './styles/_variables.scss'),
],
},
},
] : []),
],
})
}
module.exports = withDotenv({
webpack: (config, options) => {
config.module.rules.push(
{
test: /\.css$/,
exclude: localStyleCondition,
use: getStyleLoaders('css', 'global', config, options),
}, {
test: /\.scss$/,
exclude: localStyleCondition,
use: getStyleLoaders('scss', 'global', config, options),
}, {
test: /\.css$/,
include: localStyleCondition,
use: getStyleLoaders('css', 'local', config, options),
}, {
test: /\.scss$/,
include: localStyleCondition,
use: getStyleLoaders('scss', 'local', config, options),
},
{
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)(\?.*|$)/,
loader: 'url-loader',
options: {
limit: 8192,
fallback: 'file-loader',
publicPath: '/_next/static/fonts/',
outputPath: 'static/fonts/',
name: '[name]-[hash].[ext]',
},
},
)
// if (!dev) {
// // eslint-disable-next-line
// config.plugins = config.plugins.filter(
// p => p.constructor.name !== 'UglifyJsPlugin'
// )
// // eslint-disable-next-line
// const Uglify = require('uglifyjs-webpack-plugin')
// config.plugins.push(
// new Uglify({
// parallel: true,
// sourceMap: true,
// })
// )
// }
return config
},
})