-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
159 lines (153 loc) · 4.28 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
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const APP_ENV = process.env.APP_ENV || 'stage';
const APP_VERSION = process.env.APP_VERSION || 'ci_not_found';
const cdnBaseUrl =
APP_ENV === 'stage'
? `https://st09417311stage-fybvhtameff0aney.z01.azurefd.net/themes/${APP_VERSION}/`
: `https://st09417311prod-ahfvbhg8cbh4frf9.z01.azurefd.net/themes/${APP_VERSION}/`;
const apiBaseUrl =
APP_ENV === 'stage'
? 'https://kpas.staging.kompetanse.udir.no/api'
: 'https://kpas.kompetanse.udir.no/api';
module.exports = (env) => {
return {
entry: {
'theme-udirdesign': [
'./src/js/settingsRoot.js',
'./src/js/account-theme.js',
],
'kompetanseportalen-udirdesign': [
'./src/js/3party/matomo.js',
'./src/js/main.js',
],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['dist', 'tmp', 'babel', 'replace'],
cleanAfterEveryBuildPatterns: ['dist/*.js.map'],
}),
new webpack.DefinePlugin({
VUECSS: JSON.stringify('index.css'),
DESIGNCSS: JSON.stringify('kompetanseportalen-udirdesign.css'),
DESIGNJS: JSON.stringify('kompetanseportalen-udirdesign.js'),
SERVER: JSON.stringify(cdnBaseUrl),
KPASAPIURL: JSON.stringify(apiBaseUrl),
ACCOUNTID: [99, 100, 102, 103, 137, 138, 139, 145],
KPAS_MERGE_LTI_ID: 845,
KPAS_IFRAME_VERSION: JSON.stringify(APP_ENV),
__VUE_OPTIONS_API__: 'true',
__VUE_PROD_DEVTOOLS__: 'false',
}),
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new CopyWebpackPlugin({
patterns: [
{
from: 'src/vue/assets/',
to: '.',
},
{
from: 'src/bitmaps/',
to: 'bitmaps/',
},
{
from: 'src/vector_images/',
to: 'vector_images/',
},
{
from: 'kpas/',
to: 'kpas/',
},
],
}),
new webpack.HotModuleReplacementPlugin(),
new VueLoaderPlugin(),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'sass-loader',
options: {
additionalData: '$urlToFile: ' + `"${cdnBaseUrl}"` + ';',
api: 'modern',
sassOptions: {
silenceDeprecations: [
'mixed-decls',
'color-functions',
'global-builtin',
'import',
],
},
},
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
extractCSS: true,
},
exclude: /node_modules/,
},
],
},
resolve: {
alias: {
setup: path.resolve(__dirname, 'src/css/setup'),
vue$: path.resolve(
__dirname,
'node_modules/vue/dist/vue.runtime.esm-bundler.js',
),
},
extensions: ['.js', '.vue'],
preferRelative: true,
modules: ['src', 'node_modules'],
},
performance: {
maxEntrypointSize: 1000000,
maxAssetSize: 1000000,
},
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin(),
new TerserPlugin({
parallel: true,
extractComments: false,
}),
],
},
};
};