forked from neos/Neos.NeosIo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
147 lines (140 loc) · 5 KB
/
webpack.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import packages from './webpack.packages';
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import GlobImporter from 'node-sass-glob-importer';
import TerserPlugin from 'terser-webpack-plugin';
const defaultInlinePath = 'Resources/Private/Templates/InlineAssets';
function config(
{
packageName = null,
filename = 'Main.js',
inline = false,
entryPath = 'Resources/Private/Fusion',
publicPath = 'Resources/Public',
hasSourceMap = true,
alias = {}
}: {
packageName?: string;
filename?: string;
inline?: boolean;
entryPath?: string;
publicPath?: string;
hasSourceMap?: boolean;
alias?: Object;
},
argv: any
): object {
const includePaths = [];
const isInlineAsset = inline || publicPath == defaultInlinePath;
const baseFilename = filename.substring(0, filename.lastIndexOf('.'));
const isProduction = argv.mode == 'production';
const distFolder = packageName ? 'DistributionPackages' : '';
hasSourceMap = isInlineAsset ? false : hasSourceMap;
packageName = packageName || '';
if (inline) {
publicPath = defaultInlinePath;
}
if (packageName) {
// We are in a monorepo
const distributionPath = path.resolve(__dirname, distFolder);
const packagesPath = path.resolve(__dirname, 'Packages');
alias[distFolder] = distributionPath;
alias['Packages'] = packagesPath;
includePaths.push(distributionPath);
includePaths.push(packagesPath);
}
includePaths.push('node_modules');
return {
mode: isProduction ? 'production' : 'development',
devtool: hasSourceMap ? (isProduction ? 'source-map' : 'nosources-source-map') : false,
stats: {
modules: false,
hash: false,
version: false,
timings: true,
chunks: false,
children: false,
source: false,
publicPath: false
},
performance: { hints: false },
entry: {
[path.join(packageName, entryPath, filename)]: './' + path.join(packageName, entryPath, filename)
},
output: {
devtoolModuleFilenameTemplate: isProduction
? 'webpack://[namespace]/[resource-path]?[loaders]'
: 'file://[absolute-resource-path]?[loaders]',
path: path.resolve(__dirname, distFolder, packageName, publicPath),
filename: path.join(isInlineAsset ? '' : 'Scripts', `${baseFilename}.js`)
},
optimization: isProduction
? {
minimizer: [
new TerserPlugin({
parallel: true
})
]
}
: {},
plugins: [
new MiniCssExtractPlugin({
filename: path.join(isInlineAsset ? '' : 'Styles', `${baseFilename}.css`)
})
],
context: path.resolve(__dirname, distFolder),
module: {
rules: [
{
test: /\.(ts|js)x?$/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
},
{
// do not test for css to prevent double builds
// when two packages depend on another
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
url: false,
sourceMap: hasSourceMap,
importLoaders: 2
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: hasSourceMap
}
},
{
loader: 'sass-loader',
options: {
sourceMap: hasSourceMap,
// absolute paths for SCSS
sassOptions: {
importer: GlobImporter(),
outputStyle: 'nested',
includePaths: includePaths
}
}
}
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx', '.ts', '.tsx', '.scss'],
// absolute paths for JS and SCSS related files
alias: alias
}
};
}
export default (env, argv) => packages.map(setting => config(setting, argv));