-
Notifications
You must be signed in to change notification settings - Fork 6
/
preact.config.js
101 lines (90 loc) · 2.5 KB
/
preact.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
import HtmlWebpackInlineSourcePlugin from 'html-webpack-inline-source-plugin';
import FileManagerPlugin from 'filemanager-webpack-plugin';
export default (config, env, helpers) => {
const fileManagerPluginOptions = {};
if (process.env.NODE_ENV === 'production') {
// inline all styles
const { plugin } =
helpers.getPluginsByName(config, 'HtmlWebpackPlugin')[0] || {};
if (plugin) {
plugin.options.inlineSource = '.(css)$';
}
config.plugins.push(new HtmlWebpackInlineSourcePlugin());
// File management
fileManagerPluginOptions.onStart = {
delete: ['./build/*.*'],
copy: []
};
fileManagerPluginOptions.onEnd = {
copy: [
{
source: './src/server.js',
destination: env.dest + '/../server.js'
},
{
source: './src/transcode.js',
destination: env.dest + '/../transcode.js'
}
]
};
}
if (config.devServer) {
config.devServer.proxy = [
{
path: '/items.json',
target: 'http://localhost:3000/items.json'
},
{
path: '/data/**',
target: 'http://localhost:3000'
}
];
}
// Remove loaders to implement own svg loader
const loader =
process.env.NODE_ENV === 'production'
? helpers.getLoadersByName(config, 'file-loader')
: helpers.getLoadersByName(config, 'url-loader');
if (loader.length > 0 && loader[0]['ruleIndex']) {
config.module.loaders.splice(loader[0]['ruleIndex'], 1);
}
config.module.loaders.push(
{
test: /\.svg$/,
use: [
{
loader: 'svgr/webpack'
},
{
loader: require.resolve('file-loader'),
options: {
name: 'svgs/[name].[hash:8].[ext]'
}
}
]
},
{
test: /\.(woff2?|ttf|eot|jpe?g|png|gif|mp4|mov|ogg|webm)(\?.*)?$/i,
loader: 'file-loader'
}
);
let API_URL;
// Configure demo mode
if (process.env.PUBLISH_ENV === 'github') {
API_URL = '/SBideo/items-demo.json';
config.output.publicPath = '/SBideo/';
fileManagerPluginOptions.onStart.copy.push({
source: './data-clientdemo',
destination: env.dest
});
}
config.plugins.push(new FileManagerPlugin(fileManagerPluginOptions));
config.plugins.push(
new helpers.webpack.DefinePlugin({
'process.env.API_URL': JSON.stringify(API_URL || '/items.json'),
'process.env.ASSET_PATH': JSON.stringify(
(config.output.publicPath || '/') + 'assets/'
)
})
);
};