forked from sulu/sulu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
147 lines (139 loc) · 5.43 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
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-nodejs-modules*/
const path = require('path');
const glob = require('glob');
const rimraf = require('rimraf');
const webpack = require('webpack');
const CleanObsoleteChunksPlugin = require('webpack-clean-obsolete-chunks');
const ManifestPlugin = require('webpack-manifest-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const {styles} = require('@ckeditor/ckeditor5-dev-utils'); // eslint-disable-line import/no-extraneous-dependencies
module.exports = (env, argv) => { // eslint-disable-line no-undef
let publicDir = 'public';
const basePath = env && env.base_path ? env.base_path : 'build/admin';
const composerConfig = require(path.resolve('composer.json')); // eslint-disable-line import/no-dynamic-require
if (composerConfig.extra && composerConfig.extra['public-dir']) {
publicDir = composerConfig.extra['public-dir'];
}
if (publicDir.startsWith('/')) {
const errorMessage = [
'\x1b[31mUsing absolute path for \x1b[0m"public-dir"\x1b[31m detected',
' This can end up in accidentally remove of files outside your project dir.',
' Build was cancelled!\x1b[0m',
'',
].join('\n');
throw new Error(errorMessage);
}
// Remove old build files
rimraf.sync(path.resolve(publicDir, basePath));
const entries = glob.sync(
path.resolve(__dirname, 'src/Sulu/Bundle/*/Resources/js/index.js') // eslint-disable-line no-undef
);
const entriesCount = entries.length;
entries.unshift('core-js/fn/array/includes');
entries.unshift('core-js/fn/array/find-index');
entries.unshift('core-js/fn/array/fill');
entries.unshift('core-js/fn/array/from');
entries.unshift('core-js/fn/promise');
entries.unshift('core-js/fn/symbol');
entries.unshift('whatwg-fetch');
entries.unshift('url-search-params-polyfill');
return {
entry: entries,
output: {
path: path.resolve(publicDir),
filename: basePath + '/[name].[chunkhash].js',
},
devtool: argv.mode === 'development' ? 'eval-source-map' : 'source-map',
plugins: [
new webpack.DefinePlugin({
BUNDLE_ENTRIES_COUNT: entriesCount,
}),
new MiniCssExtractPlugin({
filename: basePath + '/[name].[chunkhash].css',
}),
new ManifestPlugin({
fileName: basePath + '/manifest.json',
}),
new CleanObsoleteChunksPlugin(),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: 'babel-loader',
},
{
test: /\.css/,
exclude: /ckeditor5-[^/]+\/theme\/[\w-/]+\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
{
test: /\.(scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
importLoaders: 1,
camelCase: true,
localIdentName: '[local]--[hash:base64:10]',
},
},
'postcss-loader',
],
},
{
test: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
use: 'raw-loader',
},
{
test: /ckeditor5-[^/]+\/theme\/[\w-/]+\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: styles.getPostCssConfig({
themeImporter: {
themePath: require.resolve('@ckeditor/ckeditor5-theme-lark'),
},
minify: true,
}),
},
],
},
{
test: /\.(svg|ttf|woff|woff2|eot)(\?.*$|$)/,
exclude: /ckeditor5-[^/]+\/theme\/icons\/[^/]+\.svg$/,
use: [
{
loader: 'file-loader',
options: {
name: '/' + basePath + '/fonts/[name].[hash].[ext]',
},
},
],
},
{
test: /\.(jpg|gif|png)(\?.*$|$)/,
use: [
{
loader: 'file-loader',
options: {
name: '/' + basePath + '/images/[name].[hash].[ext]',
},
},
],
},
],
},
};
};