forked from neonexus/sails-react-bootstrap-webpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.config.js
More file actions
158 lines (143 loc) · 4.53 KB
/
Copy pathcommon.config.js
File metadata and controls
158 lines (143 loc) · 4.53 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
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
155
156
157
158
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const _ = require('lodash');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
let configPath = path.resolve(__dirname, '../local.js'),
baseUrl = 'http://localhost:1337',
frontendUrl = 'http://localhost:8080',
assetUrl = '';
try {
let config = {};
if (fs.existsSync(configPath)) {
config = require(configPath);
} else {
configPath = (process.env.NODE_ENV !== 'production')
? path.resolve(__dirname, '../env/development.js')
: path.resolve(__dirname, '../env/production.js');
config = require(configPath);
}
baseUrl = config.baseUrl;
frontendUrl = config.frontendUrl;
assetUrl = config.assetsUrl ? config.assetsUrl : '/';
} catch (err) {
return console.error(err);
}
const baseHtmlConfig = {
template: 'assets/entry_template.html',
inject: true,
hash: true,
minify: process.env.NODE_ENV === 'production',
publicPath: assetUrl
};
const entryPoints = [
{
name: 'admin',
entry: path.join(__dirname, '/../../assets/src/admin.jsx'),
outfile: 'admin/index.html',
title: 'My Admin',
template: 'assets/webapp_entry_template.html'
},
{
// this entry is mainly for local development, and won't be served by Sails
name: 'index',
entry: path.join(__dirname, '/../../assets/src/index.jsx'),
outfile: 'index.html',
title: 'My Application'
},
{
name: 'main',
entry: path.join(__dirname, '/../../assets/src/main.jsx'),
outfile: 'main/index.html',
title: 'My Application'
}
];
let entry = {},
plugins = [];
for (let i = 0; i < entryPoints.length; ++i) {
const template = (entryPoints[i].template) ? entryPoints[i].template : baseHtmlConfig.template;
if (!entryPoints[i].include || !_.isArray(entryPoints[i])) {
entryPoints[i].include = [entryPoints[i].name];
}
entry[entryPoints[i].name] = entryPoints[i].entry;
plugins.push(new HtmlWebpackPlugin(_.merge({}, baseHtmlConfig, {filename: entryPoints[i].outfile, chunks: entryPoints[i].include, template})));
}
plugins.push(
new webpack.DefinePlugin({
'process.env': JSON.stringify({
baseUrl,
frontendUrl
})
})
);
plugins.push(new FaviconsWebpackPlugin({
logo: path.join(__dirname, '/../../assets/images/favicon.png'), // svg works too!
mode: 'webapp', // 'webapp' or 'light' - 'webapp' by default
devMode: 'light', // 'webapp' or 'light' - 'light' by default
favicons: {
appName: 'sails-react-bootstrap-webpack',
appDescription: 'A great start to an awesome application.',
developerName: null,
developerURL: null, // prevent retrieving from the nearest package.json
display: 'standalone', // Preferred display mode: "fullscreen", "standalone", "minimal-ui" or "browser".
background: '#fff',
theme_color: '#fff',
icons: {
coast: false,
yandex: false
}
}
}));
plugins.push(
new CopyPlugin({
patterns: [
{from: path.join(__dirname, '/../../assets/fonts'), to: path.join(__dirname, '/../../.tmp/public/assets/fonts')}
]
})
);
module.exports = {
entry,
plugins,
output: {
path: path.join(__dirname, '/../../.tmp/public'),
filename: '[name]/bundle.js',
publicPath: baseHtmlConfig.publicPath
},
module: {
rules: [
{
test: /\.jsx$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpe?g|gif)$/i,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'assets/images'
}
}
]
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
modules: ['node_modules', path.join(__dirname, '/../../assets')]
},
optimization: {
splitChunks: {
// chunks: 'all',
cacheGroups: {
styles: {
test: /\.(css|scss|sass)$/,
enforce: true // force css in new chunks (ignores all other options)
}
}
}
}
};