Created
August 24, 2020 14:11
-
-
Save budarin/f344f8df16015d682757fc7b85b434b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); | |
const { DuplicatesPlugin } = require('inspectpack/plugin'); | |
const { UnusedFilesWebpackPlugin } = require('unused-files-webpack-plugin'); | |
const CircularDependencyPlugin = require('circular-dependency-plugin'); | |
const nodeExternals = require('webpack-node-externals'); | |
const babelConfig = require('../../babel/server.babel.config'); | |
const cacheDir = path.resolve('./node_modules/.cache'); | |
const getThreadLoader = (name) => ({ | |
loader: 'thread-loader', | |
options: { | |
name, | |
}, | |
}); | |
const includePaths = [path.resolve('./src/common'), path.resolve('./src/server')]; | |
module.exports = { | |
name: 'server_dev', | |
watch: false, | |
cache: true, | |
target: 'node', | |
profile: false, | |
mode: 'development', | |
devtool: 'eval-source-map', | |
entry: { server: './src/server/index.ts' }, | |
output: { | |
path: path.resolve('./dist'), | |
filename: 'server.js', | |
chunkFilename: '[name].js', | |
libraryTarget: 'commonjs2', | |
}, | |
resolve: { | |
extensions: ['.ts', '.tsx', '.js', '.json'], | |
modules: ['node_modules'], | |
alias: { | |
depd: path.resolve('./node_modules/depd'), | |
'koa-compose': path.resolve('./node_modules/koa-compose'), | |
'supports-color': path.resolve('./node_modules/supports-color'), | |
'has-flag': path.resolve('./node_modules/has-flag'), | |
debug: path.resolve('./node_modules/debug'), | |
'ms@': path.resolve('./node_modules/ms@'), | |
ioredis: 'ioredis/built/redis', | |
extsprintf: path.resolve('./node_modules/extsprintf'), | |
qs: path.resolve('./node_modules/qs'), | |
'safe-buffer': path.resolve('./node_modules/safe-buffer'), | |
// dev only for koa-static | |
'http-errors': path.resolve('./node_modules/http-errors'), | |
inherits: path.resolve('./node_modules/inherits'), | |
setprototypeof: path.resolve('./node_modules/setprototypeof'), | |
}, | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.(ts|tsx|js|jsx|json)$/, | |
include: includePaths, | |
exclude: /node_modules/, | |
use: [ | |
getThreadLoader('dev-server-js'), | |
{ | |
loader: 'babel-loader', | |
options: Object.assign({}, babelConfig, { | |
babelrc: false, | |
cacheDirectory: path.resolve(cacheDir, 'server'), | |
}), | |
}, | |
], | |
}, | |
{ | |
test: /\.css$/, | |
include: includePaths, | |
exclude: /node_modules/, | |
use: [ | |
{ | |
loader: 'cache-loader', | |
options: { | |
cacheDirectory: path.resolve(cacheDir, 'dev-server-css'), | |
}, | |
}, | |
// getThreadLoader('dev-server-css'), | |
'fake-style-loader', | |
{ | |
loader: 'css-loader', | |
options: { | |
importLoaders: 1, | |
modules: { | |
mode: 'local', | |
localIdentName: '[folder].[name].[local]', | |
}, | |
}, | |
}, | |
{ | |
loader: 'postcss-loader', | |
options: {}, | |
}, | |
], | |
}, | |
], | |
}, | |
externals: [nodeExternals()], | |
plugins: [ | |
// https://github.com/serverless-heaven/serverless-webpack/issues/78 | |
new webpack.IgnorePlugin(/^pg-native$/), | |
new webpack.DefinePlugin({ | |
__PROD__: false, | |
__SERVER__: true, | |
__CLIENT__: false, | |
// https://github.com/felixge/node-formidable/issues/337 | |
'global.GENTLY': false, | |
}), | |
new UnusedFilesWebpackPlugin({ | |
failOnUnused: false, | |
patterns: ['./src/server/**/*.*'], | |
globOptions: { | |
ignore: [ | |
'node_modules/**/*', | |
'./src/types/*', | |
'./src/server/config/*', | |
'./src/server/jest.config.js', | |
'./src/**/__tests__/*', | |
'./src/**/*.test.ts', | |
], | |
}, | |
}), | |
new DuplicatesPlugin(), | |
new CircularDependencyPlugin({ | |
// exclude detection of files based on a RegExp | |
exclude: /node_modules|lazyComponentBabelPlugin\.js/, | |
// add errors to webpack instead of warnings | |
failOnError: true, | |
// allow import cycles that include an asyncronous import, | |
// e.g. via import(/* webpackMode: "weak" */ './file.js') | |
allowAsyncCycles: false, | |
}), | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment