next.config.js 1.8 KB
Newer Older
1
/* eslint-disable @typescript-eslint/no-var-requires */
2

3 4 5 6 7
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 已提交
8
const distDir = 'dist';
9 10 11 12 13 14 15 16 17 18

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

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

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

50 51 52
        config.resolve = config.resolve || {};
        config.resolve.alias = config.resolve.alias || {};
        config.resolve.alias['~'] = path.resolve(__dirname);
53 54

        config.node = Object.assign({}, config.node, {
P
Peter Pan 已提交
55
            // eslint-disable-next-line @typescript-eslint/naming-convention
56 57 58 59 60 61 62 63 64 65 66
            child_process: 'empty',
            fs: 'empty'
        });

        config.plugins = [
            ...(config.plugins || []),
            new WorkerPlugin({
                globalObject: 'self'
            })
        ];

67 68 69
        return config;
    }
};