-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack-dev-server.js
63 lines (53 loc) · 1.46 KB
/
webpack-dev-server.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
'use strict'
const webpack = require('webpack')
const clone = require('clone')
// clone the webpack config to separate configuration of webpack and dev server
const webpackConfig = clone(require('./webpack').options)
// Path module provides utilities for working with file and directory path
const path = require('path')
// Turns any callback into a Webpack Plugin
const WebpackOnBuildPlugin = require('on-build-webpack')
// Opens a new browser tab when Webpack loads, will be used in
// WebpackOnBuildPlugin callback
const opn = require('opn')
// allows `opn` to only open the browser on the first build
let firstBuild = true
// port for development server
const port = 7165
// make `jQuery` and `$` available in the development console
webpackConfig.module.rules.push({
test: require.resolve('jquery'),
use: [{
loader: 'expose-loader',
options: 'jQuery'
}, {
loader: 'expose-loader',
options: '$'
}]
})
module.exports = {
options: {
port,
inline: true, // reload on change
webpack: webpackConfig,
publicPath: '/public/',
contentBase: [ path.join(__dirname, '/../') ],
watchContentBase: true
},
start: {
webpack: {
devtool: 'source-map',
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
}),
new WebpackOnBuildPlugin(function () {
if (firstBuild) {
opn('http://localhost:' + port)
}
firstBuild = false
})
]
}
}
}