-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
160 lines (149 loc) · 6.35 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
155
156
157
158
159
160
const ExtractTextPlugin = require("extract-text-webpack-plugin");
var WebpackPreBuildPlugin = require('pre-build-webpack');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
let find = require('find');
let fs = require('fs');
var WebpackPreBuildPlugin = require('pre-build-webpack');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const {
ReactLoadablePlugin
} = require("@jahredhope/react-loadable-webpack-plugin");
module.exports = env => {
return {
entry: {
app: ['./index.js', './assets/vendor/bootstrap/bootstrap.min.css', './assets/vendor/icon-awesome/css/font-awesome.min.css', './assets//vendor/icon-hs/style.css', './assets/vendor/dzsparallaxer/dzsparallaxer.css', './assets/vendor/dzsparallaxer/dzsscroller/scroller.css', './assets/vendor/dzsparallaxer/advancedscroller/plugin.css', './assets/vendor/animate.css', './assets/vendor/hs-megamenu/src/hs.megamenu.css', './assets/vendor/hamburgers/hamburgers.min.css', './assets/css/unify.css', './assets/css/custom.css'
/*
,'./assets/vendor/tether.min.js'
,'./assets/vendor/bootstrap/bootstrap.min.js'
,'./assets/vendor/hs-megamenu/src/hs.megamenu.js'
,'./assets/vendor/dzsparallaxer/dzsparallaxer.js'
,'./assets/vendor/dzsparallaxer/dzsscroller/scroller.js'
,'./assets/vendor/dzsparallaxer/advancedscroller/plugin.js'
,'./assets/vendor/typedjs/typed.min.js'
,'./assets/js/hs.core.js'
,'./assets/js/components/hs.header.js'
,'./assets/js/helpers/hs.hamburgers.js'
,'./assets/js/components/hs.go-to.js'*/
]
//,'./public/city_guide.scss','./public/awesomplete.css'
},
target: "web",
devServer: {
historyApiFallback: true,
},
devtool: 'source-map',
optimization: {
minimizer: [ new OptimizeCSSAssetsPlugin({}),new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
parse: {},
compress: {
reduce_vars: false,
collapse_vars: false
},
mangle: true, // Note `mangle.properties` is `false` by default.
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_fnames: false,
},
}),]
},
output: {
path: __dirname + '/.compiled/Components',
filename: '[name].bundle.js',
publicPath: '/'
},
mode: 'development',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.jsx$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
}
,
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it uses publicPath in webpackOptions.output
publicPath: '../',
hmr: process.env.NODE_ENV === 'development',
},
},
'css-loader',
],
},
{
test: /\.(png|jpg|gif|cur|woff|eot|ttf|svg|dtd|woff2)$/,
use: [{
loader: 'url-loader'
}]
}
]
},
plugins: [
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'bundle.css',
}), new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
}),
new ReactLoadablePlugin({
filename: "react-loadable.json"
}),
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(env.NODE_ENV)
}),
new WebpackPreBuildPlugin(function (stats) {
console.log('Reducer build');
let dirname = __dirname + ''
let files = find.fileSync('reducer.js', dirname);
let result = files.map(item => {
let result = item.replace(dirname, '.').replace(/\\/g, '/');
let size = result.split('/').length;
return {
name: result.split('/')[size - 2] + 'Reducer',
path: result
}
})
let exportTxt = ' export default {';
exportTxt += result.map(item => { return item.name }).join(',');
exportTxt += '}';
let importTxt = result.map(item => { return `import ${item.name} from '${item.path}';\n` }).join(' ')
try {
let filebody = fs.readFileSync(dirname + '/reducers.scenes.js');
if (filebody.toString() == `${importTxt}${exportTxt}`) {
return;
}
} catch (ex) {
console.log(ex);
}
const data = new Uint8Array(Buffer.from(`${importTxt}${exportTxt}`));
fs.writeFileSync(dirname + '/reducers.scenes.js', data);
console.log('REDUCES FINISHED');
// import( __dirname.replace(/\\/g,'/')+'/build_reducers.js');
// Do whatever you want before build starts...
})
]
};
}