-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-config.js
154 lines (140 loc) · 3.78 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
const _ = require('lodash')
const path = require('path')
const DM = require('./index.js')
const PM = require('@ff0000-ad-tech/wp-process-manager')
const IndexVariationResolvePlugin = require('@ff0000-ad-tech/wp-resolve-plugin-index-variation')
const debug = require('@ff0000-ad-tech/debug')
var log = debug('DM:webpack.config.js')
/**
* WEBPACK >>
* For config info, see https://github.com/ff0000-ad-tech/wp-creative-server
*/
/**
* NOTE!! This is NOT webpack.config.js!
*
* This module intended to be required into a real webpack.config.js
*/
const execute = async (config) => {
if (config) {
config = JSON.parse(config)
} else {
config = {}
}
/** -- PROCESS MANAGEMENT ----
*
* keep this script in sync with Creative Server
*
*/
PM.prepare(config.watch)
PM.startWatching()
/** -- COMPILATION SCOPE ----
*
*
*/
log(``)
log(`Compilation Scope:`)
log(config.scope)
/** -- DEPLOY SETTINGS ----
*
* Config is derived from:
* - these base settings
* - config object passed to webpack from Creative-Server
* - Index settings read by Deploy-Manager
*
*/
DM.deploy.prepare(
_.merge(
{
// deploy profile
profile: {
name: 'default'
},
// the context from which the ad will subload its assets
// NOTE: deploy.config.env is passed from Creative Server by default
env: {
runPath: '',
adPath: ''
},
// source
source: {
context: './1-build',
common: 'common',
size: '300x250',
index: 'index.html'
// path: // derived from [source.context][source.size][source.index]
// name: 'index' // if not specified, this will be derived from [source.index]
},
// output
output: {
debug: true,
context: './2-debug'
// folder: '' // if not specified, this will be derived from [source.size]__[source.name]
}
},
config.deploy
)
)
// discovered ad settings are added here
// see index.html hooks for more info
// NOTE: config.deploy.settings can override what's in the index
DM.deploy.get().settings = await DM.adManager.applyIndexSettings(config.scope, DM.deploy.get())
log(``)
log('DM.deploy Config:')
log(DM.deploy.get())
/** -- CONTEXT ----
*
*
*
*/
const sourceContext = path.resolve(config.scope, DM.deploy.get().source.context)
const outputContext = path.resolve(config.scope, DM.deploy.get().output.context)
/** -- WEBPACK RUNTIME ----
*
*
*
*/
return {
mode: DM.deploy.get().output.debug ? 'development' : 'production',
entry: {
// are injected into index.html, via wp-plugin-index
initial: `${sourceContext}/node_modules/@ff0000-ad-tech/ad-entry/index.js`,
inline: `${sourceContext}/${DM.deploy.get().source.size}/.inline-imports.js`,
// is bundled & polite-loaded into index.html
build: `${sourceContext}/${DM.deploy.get().source.size}/build.js`
},
output: {
path: `${outputContext}/${DM.deploy.get().output.folder}`,
filename: '[name].bundle.js'
},
resolve: {
// mainFields: ['module', 'main', 'browser'],
extensions: ['.js', '.jsx'],
alias: Object.assign({
'@common': `${sourceContext}/common`,
'@size': `${sourceContext}/${DM.deploy.get().source.size}`
}),
plugins: [new IndexVariationResolvePlugin(DM.deploy.get().source.index.replace('.html', ''))],
modules: ['node_modules', path.resolve(__dirname, 'node_modules')]
},
module: {
rules: DM.babel.getBabel({
root: __dirname
})
},
plugins: DM.plugins.getPlugins({
scope: config.scope,
DM,
PM,
fbaCompile: DM.deploy.get().profile.fbaCompile
}),
externals: {
'ad-global': 'window'
},
optimization: DM.optimization.getOptimization({ optimize: DM.deploy.get().profile.optimize }),
watch: DM.deploy.get().output.debug,
devtool: DM.deploy.get().output.debug ? 'source-map' : false
}
}
module.exports = {
execute
}