forked from sulu/sulu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
180 lines (174 loc) · 7.46 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-nodejs-modules */
/* eslint-disable import/no-dynamic-require */
const fs = require('fs');
const path = require('path');
module.exports = (env, argv) => { // eslint-disable-line no-undef
env = env ? env : {};
argv = argv ? argv : {};
const outputPath = env && env.output_path ? env.output_path : path.join('build', 'admin');
// eslint-disable-next-line no-undef
const projectRootPath = env && env.project_root_path ? env.project_root_path : __dirname;
const nodeModulesPath = env && env.node_modules_path
? env.node_modules_path
: path.resolve(projectRootPath, 'node_modules');
let publicDir = 'public';
const composerConfig = require(path.resolve(projectRootPath, 'composer.json'));
if (composerConfig.extra && composerConfig.extra['public-dir']) {
publicDir = composerConfig.extra['public-dir'];
}
// default value for version must match default value in SuluVersionPass.php
let suluVersion = '_._._';
if (fs.existsSync(path.resolve(projectRootPath, 'composer.lock'))) {
const composerLock = JSON.parse(fs.readFileSync(path.resolve(projectRootPath, 'composer.lock')));
const suluPackage = composerLock.packages.find((packageItem) => packageItem.name === 'sulu/sulu');
suluVersion = suluPackage ? suluPackage.version : suluVersion;
}
const webpack = require(path.resolve(nodeModulesPath, 'webpack'));
const ManifestPlugin = require(path.resolve(nodeModulesPath, 'webpack-manifest-plugin')).WebpackManifestPlugin;
const MiniCssExtractPlugin = require(path.resolve(nodeModulesPath, 'mini-css-extract-plugin'));
const CssMinimizerPlugin = require(path.resolve(nodeModulesPath, 'css-minimizer-webpack-plugin'));
const {styles} = require(path.resolve(nodeModulesPath, '@ckeditor/ckeditor5-dev-utils'));
return {
entry: [path.resolve(__dirname, 'index.js')], // eslint-disable-line no-undef
output: {
clean: true,
path: path.resolve(projectRootPath, publicDir, outputPath),
filename: '[name].[chunkhash].js',
},
stats: 'minimal',
performance: {
hints: false,
},
snapshot: {
// detect changes in "node_modules/@sulu": https://github.com/webpack/webpack/issues/11612
managedPaths: [],
},
devtool: argv.mode === 'development' ? 'eval-source-map' : 'source-map',
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[chunkhash].css',
}),
new CssMinimizerPlugin(),
new ManifestPlugin({
map: (file) => {
// see https://github.com/shellscape/webpack-manifest-plugin/issues/229
file.path = file.path.replace(/^auto\//, '/' + outputPath + '/');
return file;
},
}),
new webpack.DefinePlugin({
SULU_ADMIN_BUILD_VERSION: JSON.stringify(suluVersion),
}),
],
optimization: {
minimizer: [
'...', // extend existing minimizers: https://webpack.js.org/plugins/css-minimizer-webpack-plugin/
new CssMinimizerPlugin(),
],
},
resolve: {
alias: {
'fos-jsrouting': path.resolve(
projectRootPath,
'vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js'
),
},
symlinks: false, // @see https://github.com/sulu/sulu/pull/6117
},
resolveLoader: {
symlinks: false, // @see https://github.com/sulu/sulu/pull/6117
},
module: {
rules: [
{
test: /\.js$/,
// eslint-disable-next-line max-len
exclude: /node_modules[/\\](?!(sulu-(.*)-bundle|@ckeditor|ckeditor5|array-move|lodash-es|vanilla-colorful)[/\\])/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
cacheCompression: false,
},
},
},
{
test: /\.css/,
exclude: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
// style loader not required: https://github.com/webpack-contrib/css-loader#recommend
// eslint-disable-next-line max-len
// https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/alternative-setups/integrating-from-source.html#option-extracting-css
'css-loader',
],
},
{
test: /\.(scss)$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
modules: {
localIdentName: '[local]--[contenthash:base64:10]',
exportLocalsConvention: 'camelCase',
},
importLoaders: 1,
},
},
'postcss-loader',
],
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
type: 'asset/source',
},
{
test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
postcssOptions: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve(
path.resolve(nodeModulesPath, '@ckeditor/ckeditor5-theme-lark')
),
},
minify: true,
}),
},
},
],
},
{
test: /\.(svg|ttf|woff|woff2|eot)(\?.*$|$)/,
exclude: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
type: 'asset/resource',
generator: {
filename: '[name].[contenthash][ext]',
},
},
{
test: /\.(jpg|gif|png)(\?.*$|$)/,
type: 'asset/resource',
generator: {
filename: 'images/[name].[contenthash][ext]',
},
},
],
},
};
};