next.config.js 1.5 KB
Newer Older
1 2 3 4 5 6
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const pkg = require('./package.json');

const publicPath = process.env.PUBLIC_PATH || '';
const apiUrl = process.env.API_URL || '/api';
P
Peter Pan 已提交
7
const distDir = 'dist';
8 9 10 11 12 13 14 15 16 17

const APP = {
    name: pkg.name,
    version: pkg.version,
    title: pkg.title,
    description: pkg.description,
    author: pkg.author,
    keywords: pkg.keywords.join(',')
};

P
Peter Pan 已提交
18 19 20 21 22
const DEFAULT_LANGUAGE = 'en';
const LOCALE_PATH = 'public/locales';
const LANGUAGES = ['en', 'zh'];
const otherLanguages = LANGUAGES.filter(lang => lang !== DEFAULT_LANGUAGE);

23
module.exports = {
24
    target: 'serverless',
25
    assetPrefix: publicPath,
P
Peter Pan 已提交
26
    distDir,
27 28 29
    poweredByHeader: false,
    env: {
        ...APP,
P
Peter Pan 已提交
30
        BUILD_ID: '',
P
Peter Pan 已提交
31 32 33
        DEFAULT_LANGUAGE,
        LOCALE_PATH,
        LANGUAGES,
34 35 36
        PUBLIC_PATH: publicPath,
        API_URL: apiUrl
    },
P
Peter Pan 已提交
37 38 39 40 41 42 43 44 45
    exportPathMap: defaultPathMap => {
        return {
            ...defaultPathMap,
            ...Object.entries(defaultPathMap).reduce((prev, [path, router]) => {
                otherLanguages.forEach(lang => (prev[`/${lang}${path}`] = router));
                return prev;
            }, {})
        };
    },
P
Peter Pan 已提交
46 47 48
    experimental: {
        basePath: publicPath
    },
49 50 51 52 53 54 55
    webpack: config => {
        config.resolve = config.resolve || {};
        config.resolve.alias = config.resolve.alias || {};
        config.resolve.alias['~'] = path.resolve(__dirname);
        return config;
    }
};