Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const WebpackCopyPlugin = require('copy-webpack-plugin');
- module.exports = (webpackEnv, argv) => {
- const env = process.env;
- const mode = argv.mode || env.NODE_ENV || 'production';
- const isProd = mode === 'production';
- const tsconfig = require(path.resolve(__dirname, 'tsconfig.json'));
- const sourceDirName = 'src';
- const outDirectoryName = tsconfig.compilerOptions.outDir || 'dist';
- const outDirectory = path.resolve(__dirname, outDirectoryName);
- return {
- mode: mode,
- target: 'node',
- devtool: isProd ? 'source-map' : 'eval',
- entry: {
- [sourceDirName + '/index']: `./${sourceDirName}/index.ts`
- },
- output: {
- filename: '[name].js',
- path: outDirectory,
- libraryTarget: 'commonjs',
- clean: true
- },
- resolve: {
- extensions: ['.ts', '.js']
- },
- module: {
- rules: [
- {
- test: /\.ts$/,
- exclude: /node_modules/,
- use: {
- loader: 'babel-loader',
- options: require(path.resolve(__dirname, 'babel.config.js'))
- },
- }
- ]
- },
- plugins: [
- ...(isProd ? [
- new WebpackCopyPlugin({
- patterns: [{
- // Provide package.json without deps to avoid installing dependencies on vercel.com.
- from: 'package.json',
- to: 'package.json',
- transform (content) {
- const packageJson = JSON.parse(content.toString('utf8'));
- delete packageJson.scripts;
- delete packageJson.dependencies;
- delete packageJson.devDependencies;
- return Buffer.from(JSON.stringify(packageJson, null, 2));
- }
- }, {
- // Rewrite vercel.json with removed `dist` path.
- from: 'vercel.json',
- to: 'vercel.json',
- transform (content) {
- const vercelJson = JSON.parse(content.toString('utf8'));
- vercelJson.builds = vercelJson.builds.map((build) => (
- Object.assign(build, {
- src: build.src.replace(outDirectoryName + path.sep, '')
- })
- ));
- vercelJson.rewrites = vercelJson.rewrites.map((rewrite) => (
- Object.assign(rewrite, {
- destination: rewrite.destination.replace(path.sep + outDirectoryName, '')
- })
- ));
- return Buffer.from(JSON.stringify(vercelJson, null, 2));
- }
- }]
- })
- ] : [
- // isDev
- ])
- ]
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement