-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnext.config.js
94 lines (85 loc) · 2.35 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
const { nextI18NextRewrites } = require('next-i18next/rewrites')
const MomentLocalesPlugin = require('moment-locales-webpack-plugin')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
const withSass = require('@zeit/next-sass')
const withLess = require('@zeit/next-less')
const withCSS = require('@zeit/next-css')
const path = require('path')
const config = require('./config')
const composeConfig = (...configs) => (defaultConfig) =>
configs.reduce(
(resultConfig, configFunc) => configFunc(resultConfig),
defaultConfig
)
const withOtherParam = (configFunc, param) => (config) =>
configFunc(Object.assign(config, param))
const isProd = process.env.NODE_ENV === 'production'
const localeSubpaths = {
en: 'en',
zh_tw: 'zh_tw',
zh_cn: 'zh_cn',
}
// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
require.extensions['.less'] = (file) => {}
}
module.exports = composeConfig(
withLess,
withOtherParam(withSass, {
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]',
},
}),
withOtherParam(withCSS, {
cssModules: true,
cssLoaderOptions: {
importLoaders: 1,
localIdentName: '[local]___[hash:base64:5]',
},
}),
withBundleAnalyzer
)({
lessLoaderOptions: {
javascriptEnabled: true,
},
webpack(config, options) {
if (!options.isServer && config.mode === 'development') {
const { I18NextHMRPlugin } = require('i18next-hmr/plugin')
config.plugins.push(
new I18NextHMRPlugin({
localesDir: path.resolve(__dirname, 'public/static/locales'),
})
)
}
config.plugins.push(new MomentLocalesPlugin())
config.resolve.modules.push(path.resolve('./'))
/* remove pixi warn */
config.module.rules.push({
test: '/.[js|ts]/',
use: [
{
loader: 'webpack-preprocessor-loader',
options: {
debug: false,
},
},
],
})
return config
},
rewrites: async () => nextI18NextRewrites(localeSubpaths),
publicRuntimeConfig: {
...config,
GOOGLE_ANALYTICS_ID: process.env.GOOGLE_ANALYTICS_ID || '',
IMAGE_CDN: process.env.IMAGE_CDN || '',
localeSubpaths,
isProd,
},
experimental: {
jsconfigPaths: true,
},
})