forked from andywer/webpack-blocks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
102 lines (93 loc) · 3.26 KB
/
index.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
/**
* Webpack base config block.
*
* @see https://webpack.github.io/docs/configuration.html
*/
const assert = require('assert-plus')
const common = require('@webpack-blocks/webpack-common')
const core = require('@webpack-blocks/core')
const webpack = require('webpack')
const webpackVersion = common.parseVersion(require('webpack/package.json').version)
exports.env = core.env
exports.group = core.group
exports.webpack = webpack
exports.createConfig = createConfig
exports.createConfig.vanilla = createVanillaConfig
exports.addPlugins = common.addPlugins
exports.customConfig = common.customConfig
exports.defineConstants = common.defineConstants
exports.entryPoint = common.entryPoint
exports.performance = common.performance
exports.resolveAliases = common.resolveAliases
exports.setContext = common.setContext
exports.setDevTool = common.setDevTool
exports.setOutput = common.setOutput
exports.sourceMaps = common.sourceMaps
/**
* Takes an array of webpack blocks and creates a webpack config out of them.
* Each webpack block is a callback function which will be invoked to return a
* partial webpack config. These partial configs are merged to create the
* final, complete webpack config that will be returned.
*
* Wraps @webpack-blocks/core's `createConfig` without `createConfig()`'s usual
* default config.
*
* @param {Function[]} configSetters Array of functions as returned by webpack blocks.
* @return {object} Webpack config object.
*/
function createVanillaConfig (configSetters) {
assert.arrayOfFunc(configSetters, '1st param passed to createConfig.vanilla() must be an array of functions.')
return core.createConfig({ webpack, webpackVersion }, [ createEmptyConfig ].concat(configSetters))
}
function createEmptyConfig () {
return {
module: {
loaders: []
},
plugins: []
}
}
/**
* Takes an array of webpack blocks and creates a webpack config out of them.
* Each webpack block is a callback function which will be invoked to return a
* partial webpack config. These partial configs are merged to create the
* final, complete webpack config that will be returned.
*
* Wraps @webpack-blocks/core's `createConfig` to provide some sane default
* configuration first.
*
* @param {Function[]} configSetters Array of functions as returned by webpack blocks.
* @return {object} Webpack config object.
*/
function createConfig (configSetters) {
assert.arrayOfFunc(configSetters, '1st param passed to createConfig() must be an array of functions.')
return core.createConfig({ webpack, webpackVersion }, [ createBaseConfig ].concat(configSetters))
}
function createBaseConfig (context) {
return {
module: {
loaders: [
{
test: context.fileType('text/css'),
loaders: [ 'style-loader', 'css-loader' ]
}, {
test: context.fileType('image'),
loaders: [ 'file-loader' ]
}, {
test: context.fileType('application/font'),
loaders: [ 'file-loader' ]
}, {
test: context.fileType('audio'),
loaders: [ 'url-loader' ]
}, {
test: context.fileType('video'),
loaders: [ 'url-loader' ]
}
]
},
plugins: [],
resolve: {
extensions: [ '.js', '.jsx', '.json' ]
}
}
}