UNPKG

react-torch

Version:

A lib to server-side render with react.

125 lines (124 loc) 4.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var fs_1 = __importDefault(require("fs")); var path_1 = __importDefault(require("path")); var webpack_1 = require("webpack"); var webpack_manifest_plugin_1 = require("webpack-manifest-plugin"); var fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin")); var SetManifestPlugin_1 = __importDefault(require("./SetManifestPlugin")); var index_1 = require("../../index"); function getConfig(config) { // Check if TypeScript is setup var appTsConfigPath = path_1.default.resolve(config.dir, 'tsconfig.json'); var useTypeScript = fs_1.default.existsSync(appTsConfigPath); var manifestPluginOption = { fileName: './assets.json', map: function (file) { // 删除 .js 后缀,方便直接使用 obj.name 来访问 if (file.name) { if (/\.js$/.test(file.name)) { file.name = file.name.slice(0, -3); } } return file; }, }; var plugins = [ new webpack_manifest_plugin_1.WebpackManifestPlugin(manifestPluginOption), new SetManifestPlugin_1.default(), new webpack_1.IgnorePlugin({ contextRegExp: /^\.\/locale$/, resourceRegExp: /moment$/, }), new webpack_1.HotModuleReplacementPlugin(), ]; // TypeScript type checking if (useTypeScript) { plugins.push(new fork_ts_checker_webpack_plugin_1.default({})); } return { mode: 'development', bail: false, target: 'web', context: config.dir, entry: { index: [ 'webpack-hot-middleware/client', path_1.default.resolve(__dirname, '../../internal/client/index'), ], }, devtool: 'eval-cheap-module-source-map', output: { path: path_1.default.join(config.dir, index_1.TORCH_DIR, index_1.TORCH_CLIENT_DIR, index_1.TORCH_PUBLIC_PATH), publicPath: "/" + index_1.TORCH_PUBLIC_PATH + "/", filename: "js/[name].js", chunkFilename: "js/[name].js", pathinfo: true, }, optimization: { splitChunks: { chunks: 'all', name: 'vendor', }, }, performance: { hints: false, maxEntrypointSize: 400000, }, module: { strictExportPresence: true, rules: [ { test: /\.(js|jsx)$/, loader: 'esbuild-loader', options: { loader: 'jsx', target: 'es2015', jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', }, }, { test: /\.(ts|tsx)$/, loader: 'esbuild-loader', options: { loader: 'tsx', target: 'es2015', jsxFactory: 'React.createElement', jsxFragment: 'React.Fragment', }, }, ], }, resolve: { alias: { '@routes': config.src, }, modules: ['node_modules'], extensions: ['.js', '.jsx', '.json', '.ts', '.tsx'], }, resolveLoader: { modules: ['node_modules'], extensions: ['.js', '.json', '.ts', '.jsx', '.tsx'], }, plugins: plugins, stats: { colors: true, all: true, assets: true, assetsSort: 'id', modules: true, modulesSpace: 12, providedExports: false, chunks: false, source: false, preset: 'verbose', logging: 'info', usedExports: false, }, }; } exports.default = getConfig;