forked from primer/react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
70 lines (64 loc) · 1.95 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
const {join} = require('path')
const withPlugins = require('next-compose-plugins')
const mdx = require('@zeit/next-mdx')
const getPageMap = require('next-page-map')
const pageExtensions = ['js', 'jsx', 'md', 'mdx']
const pageMap = getPageMap(join(__dirname, 'pages'), pageExtensions)
const assetPrefix = process.env.NOW_URL
module.exports = withPlugins([
mdx({extension: /\.mdx?$/})
], {
/*
* Note: Prefixing assets with the fully qualified deployment URL
* makes them available even when the site is served from a path alias, as in
* <https://primer.style/components>
*/
assetPrefix: process.env.NOW_URL,
pageExtensions,
publicRuntimeConfig: {
assetPrefix,
pageMap
},
webpack(config, {dev}) {
config.module.rules.push({
test: /\.svg$/,
use: {loader: '@svgr/webpack'}
})
if (dev) {
/*
* In development mode, we want to alias the project-root
* imports to the source files so that this:
*
* ```js
* import {Box} from '..'
* ```
*
* becomes:
*
* ```js
* import {Box} from '../src'
* ```
*
* Note: the '$' at the end of these tells webpack to match
* the end of the import path. Without it, the first alias
* applies to *every* import because the resolved path for
* every one begins with `__dirname`.
*/
config.resolve.alias = {
[__dirname + '$']: join(__dirname, 'src/index.js'),
[join(__dirname, 'css$')]: join(__dirname, 'src/css.js')
}
}
const {optimization} = config
if (optimization && Array.isArray(optimization.minimizer)) {
const terserPlugin = optimization.minimizer[0]
/* eslint-disable camelcase, no-console */
console.warn('*** disabling mangling in Terser plugin ***')
terserPlugin.options.terserOptions = {
keep_fnames: true
}
/* eslint-enable camelcase, no-console */
}
return config
}
})