1
|
|
|
'use strict'; |
2
|
|
|
const path = require('path'); |
3
|
|
|
|
4
|
|
|
const paths = {}; |
5
|
|
|
paths.THEME_PATH = path.resolve(__dirname, '../web/app/themes/stash/') + '/'; |
6
|
|
|
paths.SRC_PATH = paths.THEME_PATH + 'src/'; |
7
|
|
|
paths.IMAGE_PATH = paths.SRC_PATH + 'images/'; |
8
|
|
|
paths.ICON_FONT_PATH = paths.SRC_PATH + 'icon-font/'; |
9
|
|
|
paths.DIST_PATH = paths.THEME_PATH + 'dist/'; |
10
|
|
|
paths.BUILD_PATH = paths.THEME_PATH + 'build/'; |
11
|
|
|
paths.BOWER_PATH = paths.THEME_PATH + 'bower/'; |
12
|
|
|
|
13
|
|
|
const argv = require('yargs').argv; |
14
|
|
|
const webpack = require('webpack'); |
15
|
|
|
|
16
|
|
|
const PROD = !!argv.production; |
17
|
|
|
|
18
|
|
|
const HOST = 'localhost'; |
19
|
|
|
const PORT = 3000; |
20
|
|
|
const themePathURl = `//${HOST}:${PORT}/web/app/themes/stash/`; |
21
|
|
|
|
22
|
|
|
module.exports = { |
23
|
|
|
debug: true, |
24
|
|
|
devtool: PROD ? 'source-map' : 'cheap-module-source-map', |
25
|
|
|
noInfo: false, |
26
|
|
|
entry: PROD ? [paths.SRC_PATH + 'js/main.js'] : |
27
|
|
|
[ |
28
|
|
|
'webpack-hot-middleware/client?http://${HOST}:${PORT}&reload=true', // reloads the page if hot module reloading fails. |
29
|
|
|
paths.SRC_PATH + 'js/main.js', |
30
|
|
|
], |
31
|
|
|
target: 'web', |
32
|
|
|
output: { |
33
|
|
|
path: paths.DIST_PATH + 'js/', |
34
|
|
|
publicPath: themePathURl, |
35
|
|
|
filename: 'main.js', |
36
|
|
|
}, |
37
|
|
|
resolveLoader: { |
38
|
|
|
modulesDirectories: ['node_modules'] |
39
|
|
|
}, |
40
|
|
|
devServer: { |
41
|
|
|
contentBase: themePathURl, |
42
|
|
|
colors: true, |
43
|
|
|
quiet: false, |
44
|
|
|
noInfo: false, |
45
|
|
|
publicPath: '/dist/', |
46
|
|
|
historyApiFallback: true, |
47
|
|
|
hot: true, |
48
|
|
|
host: HOST, |
49
|
|
|
port: PORT |
50
|
|
|
}, |
51
|
|
|
plugins: PROD ? |
52
|
|
|
[ |
53
|
|
|
new webpack.optimize.OccurenceOrderPlugin(), |
54
|
|
|
new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify('production')}), |
55
|
|
|
new webpack.optimize.DedupePlugin(), |
56
|
|
|
new webpack.optimize.UglifyJsPlugin({compress: {warnings: false}}) |
57
|
|
|
] : |
58
|
|
|
[ |
59
|
|
|
new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify('development')}), |
60
|
|
|
new webpack.optimize.OccurenceOrderPlugin(), // recommended by webpack-dev-middleware |
61
|
|
|
new webpack.HotModuleReplacementPlugin(), // the magic |
62
|
|
|
new webpack.NoErrorsPlugin(), // prevents a chunk from being created with breaking (syntax, etc) errors |
63
|
|
|
|
64
|
|
|
// // unnecessary, but nice. |
65
|
|
|
// // Webpack normally doesn't output files during the dev build, this will output your assets to your build path |
66
|
|
|
// // If you visit the local wp URL instead of the proxy, your assets will be there |
67
|
|
|
// new WriteFilePluginn() |
68
|
|
|
], |
69
|
|
|
module: { |
70
|
|
|
loaders: [ |
71
|
|
|
{ |
72
|
|
|
test: /\.js$/, |
73
|
|
|
include: [ |
74
|
|
|
paths.SRC_PATH, |
75
|
|
|
path.resolve(__dirname, '../node_modules') |
76
|
|
|
], |
77
|
|
|
loaders: ['babel'], |
78
|
|
|
plugins: ['transform-runtime'], |
79
|
|
|
} |
80
|
|
|
] |
81
|
|
|
} |
82
|
|
|
}; |