1 | // node modules |
||
2 | const merge = require('webpack-merge'); |
||
3 | const path = require('path'); |
||
4 | const sane = require('sane'); |
||
5 | const webpack = require('webpack'); |
||
6 | |||
7 | // webpack plugins |
||
8 | const Dashboard = require('webpack-dashboard'); |
||
9 | const DashboardPlugin = require('webpack-dashboard/plugin'); |
||
10 | const dashboard = new Dashboard(); |
||
11 | |||
12 | // config files |
||
13 | const common = require('./webpack.common.js'); |
||
14 | const pkg = require('./package.json'); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
15 | const settings = require('./webpack.settings.js'); |
||
16 | |||
17 | // Configure the webpack-dev-server |
||
18 | const configureDevServer = () => { |
||
19 | return { |
||
20 | public: settings.devServerConfig.public(), |
||
21 | contentBase: path.resolve(__dirname, settings.paths.templates), |
||
22 | host: settings.devServerConfig.host(), |
||
23 | port: settings.devServerConfig.port(), |
||
24 | https: !!parseInt(settings.devServerConfig.https()), |
||
25 | disableHostCheck: true, |
||
26 | quiet: true, |
||
27 | hot: true, |
||
28 | hotOnly: true, |
||
29 | overlay: true, |
||
30 | stats: 'errors-only', |
||
31 | watchOptions: { |
||
32 | poll: !!parseInt(settings.devServerConfig.poll()), |
||
33 | ignored: /node_modules/, |
||
34 | }, |
||
35 | headers: { |
||
36 | 'Access-Control-Allow-Origin': '*' |
||
37 | }, |
||
38 | // Use sane to monitor all of the templates files and sub-directories |
||
39 | before: (app, server) => { |
||
40 | const watcher = sane(path.join(__dirname, settings.paths.templates), { |
||
41 | glob: ['**/*'], |
||
42 | poll: !!parseInt(settings.devServerConfig.poll()), |
||
43 | }); |
||
44 | watcher.on('change', function(filePath, root, stat) { |
||
0 ignored issues
–
show
|
|||
45 | console.log(' File modified:', filePath); |
||
0 ignored issues
–
show
|
|||
46 | server.sockWrite(server.sockets, "content-changed"); |
||
47 | }); |
||
48 | }, |
||
49 | }; |
||
50 | }; |
||
51 | |||
52 | // Configure Image loader |
||
53 | const configureImageLoader = () => { |
||
54 | return { |
||
55 | test: /\.(png|jpe?g|gif|svg|webp)$/i, |
||
56 | use: [ |
||
57 | { |
||
58 | loader: 'file-loader', |
||
59 | options: { |
||
60 | name: 'img/[name].[ext]' |
||
61 | } |
||
62 | } |
||
63 | ] |
||
64 | }; |
||
65 | }; |
||
66 | |||
67 | // Configure optimization |
||
68 | const configureOptimization = () => { |
||
69 | return { |
||
70 | splitChunks: { |
||
71 | cacheGroups: { |
||
72 | vendor: { |
||
73 | test: /node_modules/, |
||
74 | chunks: "initial", |
||
75 | name: "vendor", |
||
76 | priority: 10, |
||
77 | enforce: true |
||
78 | } |
||
79 | } |
||
80 | }, |
||
81 | }; |
||
82 | }; |
||
83 | |||
84 | // Configure the Postcss loader |
||
85 | const configurePostcssLoader = () => { |
||
86 | return { |
||
87 | test: /\.(pcss|css)$/, |
||
88 | use: [ |
||
89 | { |
||
90 | loader: 'style-loader', |
||
91 | }, |
||
92 | { |
||
93 | loader: 'vue-style-loader', |
||
94 | }, |
||
95 | { |
||
96 | loader: 'css-loader', |
||
97 | options: { |
||
98 | importLoaders: 2, |
||
99 | sourceMap: true |
||
100 | } |
||
101 | }, |
||
102 | { |
||
103 | loader: 'resolve-url-loader' |
||
104 | }, |
||
105 | { |
||
106 | loader: 'postcss-loader', |
||
107 | options: { |
||
108 | sourceMap: true |
||
109 | } |
||
110 | } |
||
111 | ] |
||
112 | }; |
||
113 | }; |
||
114 | |||
115 | // Development module exports |
||
116 | module.exports = [ |
||
117 | merge( |
||
118 | common.legacyConfig, |
||
119 | { |
||
120 | output: { |
||
121 | filename: path.join('./js', '[name].js'), |
||
122 | publicPath: settings.devServerConfig.public() + '/', |
||
123 | }, |
||
124 | resolve: { |
||
125 | alias: { |
||
126 | 'vue$': 'vue/dist/vue.js' |
||
127 | } |
||
128 | }, |
||
129 | mode: 'development', |
||
130 | devtool: 'inline-source-map', |
||
131 | optimization: configureOptimization(), |
||
132 | devServer: configureDevServer(), |
||
133 | module: { |
||
134 | rules: [ |
||
135 | configurePostcssLoader(), |
||
136 | configureImageLoader(), |
||
137 | ], |
||
138 | }, |
||
139 | plugins: [ |
||
140 | new webpack.HotModuleReplacementPlugin(), |
||
141 | new DashboardPlugin(dashboard.setData), |
||
142 | ], |
||
143 | } |
||
144 | ), |
||
145 | ]; |
||
146 |