-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebpack.config.js
More file actions
100 lines (92 loc) · 2.55 KB
/
webpack.config.js
File metadata and controls
100 lines (92 loc) · 2.55 KB
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
const fs = require('fs')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const path = require('path')
const WebpackPreBuildPlugin = require('pre-build-webpack')
const PATHS = {
COMPONENTS: './app/components',
FIELD_COMPONENT_LIST: './app/lib/field-components.js'
}
module.exports = {
entry: './app/index.js',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)(\?.*$|$)/,
use: {
loader: 'url-loader'
}
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
{
loader: 'postcss-loader',
options: {
plugins() {
return [require('autoprefixer')]
}
}
}
]
}
]
},
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new MiniCssExtractPlugin({
chunkFilename: '[id].css',
filename: '[name].css'
}),
// Build JS file with field components.
new WebpackPreBuildPlugin(() => {
const components = fs.readdirSync(PATHS.COMPONENTS).filter(item => {
return item.indexOf('Field') === 0
})
let componentsFile =
'/* eslint-disable */\n/* Generated by Webpack. Do not change or commit! */\n'
componentsFile += components
.map(component => {
const componentPath = path.resolve(
__dirname,
PATHS.COMPONENTS,
component,
component
)
return `import * as ${component} from '${componentPath}'`
})
.join('\n')
componentsFile += `\n\nexport {${components.join(', ')}}`
fs.writeFileSync(PATHS.FIELD_COMPONENT_LIST, componentsFile)
})
],
resolve: {
alias: {
'@dadi/edit-ui': path.resolve(__dirname, 'app/edit-ui'),
actions: path.resolve(__dirname, 'app/actions'),
components: path.resolve(__dirname, 'app/components'),
containers: path.resolve(__dirname, 'app/containers'),
lib: path.resolve(__dirname, 'app/lib'),
reducers: path.resolve(__dirname, 'app/reducers'),
shared: path.resolve(__dirname, 'shared'),
views: path.resolve(__dirname, 'app/views')
},
extensions: ['*', '.js', '.jsx']
}
}