-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
111 lines (105 loc) · 3.08 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
const fs = require( 'fs/promises' );
const path = require( 'path' );
const toml = require( 'toml' );
const { merge } = require( 'webpack-merge' );
const CommonConfig = require( './webpack.common.js' );
const webpack = require( 'webpack' );
const { exec } = require( 'child_process' );
const webpackBuildApiRoute = require( './webpack/build_api' );
const { campaignInfoToCampaignConfig } = require( './webpack/convert_info_to_type' );
const StyleLintPlugin = require( 'stylelint-webpack-plugin' );
const getBranch = () => new Promise( ( resolve ) => {
return exec( 'git rev-parse --abbrev-ref HEAD', ( err, stdout ) => {
if ( err ) {
console.log( `getBranch Error: ${err}` );
resolve( `UNKNOWN - ${err}` );
} else if ( typeof stdout === 'string' ) {
resolve( stdout.trim() );
}
} );
} );
// eslint-disable-next-line security/detect-non-literal-fs-filename
const readCampaignFile = ( fileName ) => fs.readFile( fileName, 'utf8' )
.then( contents => toml.parse( contents ) );
module.exports = ( env ) => Promise.all( [
getBranch(),
readCampaignFile( env.campaign_info ?? 'campaign_info.toml' )
] ).then( ( [ currentBranch, campaignConfig ] ) => merge(
CommonConfig( env ),
{
mode: 'development',
entry: {
dashboard: './dashboard/dashboard.ts',
// eslint-disable-next-line camelcase
inject_tracking: './dashboard/inject_tracking.ts'
},
resolve: {
alias: {
'@environment': path.resolve( __dirname, 'src/environment/dev/' )
}
},
plugins: [
new webpack.DefinePlugin( {
CAMPAIGNS: JSON.stringify( campaignInfoToCampaignConfig( campaignConfig ) ),
GIT_BRANCH: JSON.stringify( currentBranch )
} ),
new StyleLintPlugin( {
files: [ '**/*.{vue,css,sss,less,scss,sass}' ]
} )
],
devServer: {
'port': 8084,
'allowedHosts': 'all',
'static': [
{
directory: path.resolve( __dirname, 'dist' ),
publicPath: '/compiled-banners/'
},
{
directory: path.resolve( __dirname, 'dashboard' ),
publicPath: '/',
serveIndex: false
}
],
'headers': {
'Access-Control-Allow-Origin': '*'
},
'proxy': [
{
context: [ '/mobile' ],
pathRewrite: { '^/mobile': '' },
target: 'https://de.m.wikipedia.org',
changeOrigin: true
},
{
context: [ '/en-mobile' ],
pathRewrite: { '^/en-mobile': '' },
target: 'https://en.m.wikipedia.org',
changeOrigin: true
},
{
context: [ '/wiki/Main_Page' ],
target: 'https://en.wikipedia.org',
changeOrigin: true
},
{
context: [ '/wikipedia.de', '/FundraisingBanners', '/img', '/js', '/style.css', '/suggest.js' ],
pathRewrite: { '^/wikipedia.de': '' },
target: 'https://www.wikipedia.de',
changeOrigin: true
},
{
context: [ '/wiki', '/w/', '/static' ],
target: 'https://de.wikipedia.org',
changeOrigin: true
}
],
'setupMiddlewares': ( middlewares, devServer ) => {
if ( !devServer ) {
throw new Error( 'webpack-dev-server is not defined' );
}
devServer.app.get( '/compile-banner/:bannerName', webpackBuildApiRoute );
return middlewares;
}
}
} ) );