-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwebpack.config.dev.js
109 lines (94 loc) · 2.91 KB
/
webpack.config.dev.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
// This is the webpack config to use during development.
// It enables the hot module replacement, the source maps and inline CSS styles.
import path from 'path'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import ErrorNotificationPlugin from 'webpack-error-notification'
import webpack from 'webpack'
import config from './src/config'
import writeAssets from './src/server/write-assets'
const assetsPath = path.resolve(__dirname, 'public')
const port = config.port + 1
module.exports = {
mode: 'development',
// devtool: "eval", // Transformed code
devtool: 'source-map', // Original code
entry: {
'main': [
'babel-polyfill',
`webpack-dev-server/client?http://${config.host}:${port}`,
'webpack/hot/only-dev-server',
'./src/client.jsx',
],
},
output: {
path: assetsPath,
filename: '[name]-bundle-[hash].js',
publicPath: `http://${config.host}:${port}/`,
},
target: 'web',
// yaml-js has a reference to `fs`, this is a workaround
node: {
fs: 'empty'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|public)/,
use: [{
loader: 'babel-loader',
options: {
plugins: [
['react-transform', {
'transforms': [{
'transform': 'react-transform-hmr',
'imports': ['react'],
'locals': ['module'],
}]
}]
]
}
}]
}
]
},
resolve: {
extensions: ['.js', '.jsx'],
},
plugins: [
// hot reload
new webpack.HotModuleReplacementPlugin(),
// print a webpack progress
new webpack.ProgressPlugin((percentage) => {
if (percentage === 1) {
process.stdout.write('Bundle is ready')
}
}),
new ErrorNotificationPlugin(process.platform === 'linux' && function(msg) {
if (!this.lastBuildSucceeded) {
require('child_process').exec('notify-send --hint=int:transient:1 Webpack ' + msg)
}
}),
new webpack.DefinePlugin({
'process.env': {
API_URL: JSON.stringify(config.apiBaseUrl),
CHANGELOG_URL: JSON.stringify(config.changelogUrl),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
PATHNAME: JSON.stringify(config.pathname),
}
}),
new webpack.ProvidePlugin({
React: 'react', // For babel JSX transformation which generates React.createElement.
}),
new CopyWebpackPlugin([
// 'to' values are relative to the public directory configured by output.path
{from: 'src/assets/style.css', to: '.'},
{from: 'node_modules/bootstrap/dist', to: 'bootstrap'},
{from: 'node_modules/highlight.js/styles/github-gist.css', to: '.'},
{from: 'node_modules/swagger-ui/dist/swagger-ui.css', to: '.'},
]),
function() {
this.plugin('done', writeAssets(path.resolve(__dirname, 'webpack-assets.json')).bind(this))
},
],
}