forked from neos/Neos.Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
114 lines (110 loc) · 4.01 KB
/
webpack.config.js
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
const packages = require('./webpack.packages');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const GlobImporter = require('node-sass-glob-importer');
const TerserPlugin = require('terser-webpack-plugin');
function config(
{
filename = 'Main.js',
entryPath = 'Resources/Private/Fusion',
publicPath = 'Resources/Public',
hasSourceMap = true
},
argv
) {
const includePaths = ['node_modules'];
const isInlineAsset = publicPath == 'Resources/Private/Templates/InlineAssets';
const baseFilename = filename.substring(0, filename.lastIndexOf('.'));
const isProduction = argv.mode == 'production';
hasSourceMap = isInlineAsset ? false : hasSourceMap;
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(entryPath, filename)]: './' + path.join(entryPath, filename)
},
output: {
devtoolModuleFilenameTemplate: isProduction
? 'webpack://[namespace]/[resource-path]?[loaders]'
: 'file://[absolute-resource-path]?[loaders]',
path: path.resolve(__dirname, 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),
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: isInlineAsset ? false : hasSourceMap,
importLoaders: 2
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: isInlineAsset ? false : hasSourceMap
}
},
{
loader: 'sass-loader',
options: {
sourceMap: isInlineAsset ? false : hasSourceMap,
// absolute paths for SCSS
sassOptions: {
importer: GlobImporter(),
includePaths: includePaths
}
}
}
]
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx', '.ts', '.tsx', '.scss']
}
};
}
module.exports = (env, argv) => packages.map(setting => config(setting, argv));