forked from sulu/sulu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
132 lines (128 loc) · 5.12 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
/* eslint-disable flowtype/require-valid-file-annotation */
/* eslint-disable import/no-nodejs-modules*/
const fs = require('fs');
const path = require('path');
const CleanObsoleteChunksPlugin = require('webpack-clean-obsolete-chunks');
const CleanWebpackPlugin = require('clean-webpack-plugin');
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
const babelConfig = JSON.parse(fs.readFileSync(path.resolve(__dirname, '.babelrc'))); // eslint-disable-line no-undef
module.exports = (env, argv) => { // eslint-disable-line no-undef
let publicDir = 'public';
const basePath = env && env.base_path ? env.base_path : 'build/admin';
const rootPath = env && env.root_path ? env.root_path : __dirname; // eslint-disable-line no-undef
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'];
}
return {
entry: [path.resolve(__dirname, 'assets/admin/index.js')], // eslint-disable-line no-undef
output: {
path: path.resolve(publicDir),
filename: basePath + '/[name].[chunkhash].js',
},
devtool: argv.mode === 'development' ? 'eval-source-map' : 'source-map',
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [path.resolve(publicDir, basePath)],
}),
new MiniCssExtractPlugin({
filename: basePath + '/[name].[chunkhash].css',
}),
new ManifestPlugin({
fileName: basePath + '/manifest.json',
}),
new CleanObsoleteChunksPlugin(),
],
resolve: {
alias: {
'fos-jsrouting': path.resolve(
rootPath,
'vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js'
),
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!(sulu-(.*)-bundle|@ckeditor|lodash-es)\/)/,
use: {
loader: 'babel-loader',
options: babelConfig,
},
},
{
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]',
},
},
],
},
],
},
};
};