aboutsummaryrefslogtreecommitdiff
path: root/webpack.common.js
blob: 612895b1251bc2ee35ded762708476fd52f42036 (plain)
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
const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const { VueLoaderPlugin } = require('vue-loader');

const assetsPath = path.resolve(__dirname, 'resources/assets/javascripts');

module.exports = {
    entry: {
        'studip-base': assetsPath + '/entry-base.js',
        'studip-statusgroups': assetsPath + '/entry-statusgroups.js',
        'studip-wysiwyg': assetsPath + '/entry-wysiwyg.js',
        'studip-installer': assetsPath + '/entry-installer.js',
        print: path.resolve(__dirname, 'resources/assets/stylesheets') + '/print.scss',
        accessibility: path.resolve(__dirname, 'resources/assets/stylesheets') + '/highcontrast.scss',
    },
    output: {
        path: path.resolve(__dirname, 'public/assets'),
        chunkFilename: 'javascripts/[id].chunk.js?h=[chunkhash]',
        filename: 'javascripts/[name].js',
        clean: {
            keep: /^(fonts|images|javascripts\/mathjax|sounds|stylesheets\/\.gitkeep)/,
        },
    },
    module: {
        rules: [
            {
                test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
                use: ['raw-loader'],
            },
            {
                test: /\.css$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader,
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            url: false,
                            importLoaders: 1,
                        },
                    },
                    {
                        loader: 'postcss-loader',
                    },
                ],
            },
            {
                test: /\.scss$/,
                use: [
                    {
                        loader: MiniCssExtractPlugin.loader,
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            url: false,
                            importLoaders: 2,
                        },
                    },
                    {
                        loader: 'postcss-loader',
                    },
                    {
                        loader: 'sass-loader',
                    },
                ],
            },
            {
                test: /\.ts$/,
                loader: 'ts-loader',
                exclude: /node_modules/,
                options: {
                    appendTsSuffixTo: [/\.vue$/],
                },
            },
            {
                test: /\.js$/,
                exclude: /node_modules|ckeditor/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        cacheDirectory: true,
                    },
                },
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader',
                options: {
                    compilerOptions: {
                        isCustomElement(tag) {
                            return ['altcha-widget'].includes(tag);
                        },
                    },
                },
            },
        ],
    },
    plugins: [
        process.env.RSDOCTOR && new RsdoctorWebpackPlugin({}),
        new CopyPlugin({
            patterns: [
                {
                    from: './node_modules/vue/dist/vue.global.prod.js',
                    to: './javascripts/vue.global.prod.js',
                },
                {
                    from: './node_modules/vuex/dist/vuex.global.prod.js',
                    to: './javascripts/vuex.global.prod.js',
                },
            ],
        }),
        new VueLoaderPlugin(),
        new MiniCssExtractPlugin({
            filename: 'stylesheets/[name].css',
            chunkFilename: 'stylesheets/[name].css?h=[chunkhash]',
            ignoreOrder: true,
        }),
        new ESLintPlugin({
            configType: 'flat',
            eslintPath: 'eslint/use-at-your-own-risk',
            exclude: [
                'node_modules',
                'resources/assets/javascripts/jquery/autoresize.jquery.min.js',
                'resources/assets/javascripts/jquery/jstree/jquery.jstree.js',
                'resources/assets/javascripts/vendor',
            ],
        }),
    ].filter(Boolean),
    resolve: {
        alias: {
            'jquery-ui/data': 'jquery-ui/ui/data',
            'jquery-ui/disable-selection': 'jquery-ui/ui/disable-selection',
            'jquery-ui/focusable': 'jquery-ui/ui/focusable',
            'jquery-ui/form': 'jquery-ui/ui/form',
            'jquery-ui/ie': 'jquery-ui/ui/ie',
            'jquery-ui/keycode': 'jquery-ui/ui/keycode',
            'jquery-ui/labels': 'jquery-ui/ui/labels',
            'jquery-ui/jquery-1-7': 'jquery-ui/ui/jquery-1-7',
            'jquery-ui/plugin': 'jquery-ui/ui/plugin',
            'jquery-ui/safe-active-element': 'jquery-ui/ui/safe-active-element',
            'jquery-ui/safe-blur': 'jquery-ui/ui/safe-blur',
            'jquery-ui/scroll-parent': 'jquery-ui/ui/scroll-parent',
            'jquery-ui/tabbable': 'jquery-ui/ui/tabbable',
            'jquery-ui/unique-id': 'jquery-ui/ui/unique-id',
            'jquery-ui/version': 'jquery-ui/ui/version',
            'jquery-ui/widget': 'jquery-ui/ui/widget',
            'jquery-ui/widgets/mouse': 'jquery-ui/ui/widgets/mouse',
            'jquery-ui/widgets/draggable': 'jquery-ui/ui/widgets/draggable',
            'jquery-ui/widgets/droppable': 'jquery-ui/ui/widgets/droppable',
            'jquery-ui/widgets/resizable': 'jquery-ui/ui/widgets/resizable',
            '@': path.resolve(__dirname, 'resources'),
        },
        extensions: ['.ts', '.vue', '.js'],
        fallback: {
            stream: require.resolve('stream-browserify'),
            buffer: require.resolve('buffer/'),
        },
    },
    externals: {
        vue: 'Vue',
        vuex: 'Vuex',
    },
    externalsType: 'global',
};