webpacker 5.1.0 → 6.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +70 -0
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +11 -16
  10. data/CHANGELOG.md +26 -0
  11. data/CONTRIBUTING.md +1 -1
  12. data/Gemfile.lock +91 -85
  13. data/README.md +18 -22
  14. data/docs/assets.md +21 -5
  15. data/docs/css.md +80 -30
  16. data/docs/deployment.md +18 -0
  17. data/docs/docker.md +2 -2
  18. data/docs/engines.md +1 -1
  19. data/docs/env.md +5 -0
  20. data/docs/es6.md +1 -1
  21. data/docs/integrations.md +2 -2
  22. data/docs/props.md +2 -38
  23. data/docs/react.md +183 -0
  24. data/docs/target.md +22 -0
  25. data/docs/testing.md +12 -1
  26. data/docs/troubleshooting.md +3 -1
  27. data/docs/typescript.md +89 -8
  28. data/docs/webpack-dev-server.md +17 -15
  29. data/docs/webpack.md +58 -107
  30. data/lib/install/config/webpack/base.js +3 -0
  31. data/lib/install/config/webpack/development.js +2 -2
  32. data/lib/install/config/webpack/production.js +2 -2
  33. data/lib/install/config/webpack/test.js +2 -2
  34. data/lib/install/config/webpacker.yml +9 -38
  35. data/lib/install/examples/{vue → vue3}/app.vue +10 -5
  36. data/lib/install/examples/vue3/hello_vue.js +15 -0
  37. data/lib/install/javascript/packs/application.css +9 -0
  38. data/lib/install/template.rb +33 -19
  39. data/lib/tasks/webpacker.rake +2 -11
  40. data/lib/tasks/webpacker/binstubs.rake +6 -4
  41. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  42. data/lib/tasks/webpacker/check_node.rake +1 -1
  43. data/lib/tasks/webpacker/check_yarn.rake +2 -3
  44. data/lib/tasks/webpacker/compile.rake +4 -2
  45. data/lib/tasks/webpacker/info.rake +12 -10
  46. data/lib/tasks/webpacker/install.rake +6 -4
  47. data/lib/tasks/webpacker/verify_install.rake +2 -1
  48. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  49. data/lib/webpacker/commands.rb +1 -1
  50. data/lib/webpacker/compiler.rb +12 -6
  51. data/lib/webpacker/configuration.rb +7 -23
  52. data/lib/webpacker/dev_server_runner.rb +23 -4
  53. data/lib/webpacker/helper.rb +51 -42
  54. data/lib/webpacker/manifest.rb +1 -1
  55. data/lib/webpacker/runner.rb +1 -0
  56. data/lib/webpacker/version.rb +1 -1
  57. data/lib/webpacker/webpack_runner.rb +7 -2
  58. data/package.json +27 -43
  59. data/package/__tests__/config.js +6 -27
  60. data/package/__tests__/development.js +18 -7
  61. data/package/__tests__/env.js +12 -4
  62. data/package/__tests__/production.js +6 -6
  63. data/package/__tests__/staging.js +7 -6
  64. data/package/__tests__/test.js +4 -5
  65. data/package/babel/preset-react.js +62 -0
  66. data/package/babel/preset.js +44 -0
  67. data/package/config.js +4 -9
  68. data/package/configPath.js +3 -0
  69. data/package/env.js +9 -4
  70. data/package/environments/__tests__/base.js +21 -36
  71. data/package/environments/base.js +67 -128
  72. data/package/environments/development.js +46 -39
  73. data/package/environments/production.js +69 -67
  74. data/package/environments/test.js +2 -2
  75. data/package/index.js +6 -6
  76. data/package/rules/babel.js +19 -10
  77. data/package/rules/coffee.js +6 -0
  78. data/package/rules/erb.js +13 -0
  79. data/package/rules/file.js +19 -18
  80. data/package/rules/index.js +24 -18
  81. data/package/rules/less.js +18 -0
  82. data/package/rules/sass.js +6 -7
  83. data/package/rules/svg.js +23 -0
  84. data/package/utils/get_style_rule.js +22 -28
  85. data/package/utils/helpers.js +3 -35
  86. data/test/compiler_test.rb +4 -11
  87. data/test/configuration_test.rb +2 -32
  88. data/test/dev_server_runner_test.rb +25 -6
  89. data/test/engine_rake_tasks_test.rb +39 -0
  90. data/test/helper_test.rb +18 -9
  91. data/test/mounted_app/Rakefile +4 -0
  92. data/test/mounted_app/test/dummy/Rakefile +3 -0
  93. data/test/mounted_app/test/dummy/bin/rails +3 -0
  94. data/test/mounted_app/test/dummy/bin/rake +3 -0
  95. data/test/mounted_app/test/dummy/config.ru +5 -0
  96. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  97. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  98. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  99. data/test/mounted_app/test/dummy/package.json +7 -0
  100. data/test/rake_tasks_test.rb +1 -10
  101. data/test/test_app/config/webpacker.yml +3 -21
  102. data/test/test_app/config/webpacker_public_root.yml +0 -1
  103. data/test/test_app/public/packs/manifest.json +18 -13
  104. data/test/test_app/some.config.js +0 -0
  105. data/test/webpack_runner_test.rb +10 -4
  106. data/webpacker.gemspec +1 -1
  107. data/yarn.lock +2657 -6224
  108. metadata +53 -70
  109. data/.travis.yml +0 -43
  110. data/lib/install/angular.rb +0 -23
  111. data/lib/install/coffee.rb +0 -25
  112. data/lib/install/config/.browserslistrc +0 -1
  113. data/lib/install/config/babel.config.js +0 -72
  114. data/lib/install/config/postcss.config.js +0 -12
  115. data/lib/install/config/webpack/environment.js +0 -3
  116. data/lib/install/elm.rb +0 -39
  117. data/lib/install/erb.rb +0 -25
  118. data/lib/install/examples/angular/hello_angular.js +0 -7
  119. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  120. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  121. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  122. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  123. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  124. data/lib/install/examples/elm/Main.elm +0 -55
  125. data/lib/install/examples/elm/hello_elm.js +0 -16
  126. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  127. data/lib/install/examples/react/babel.config.js +0 -87
  128. data/lib/install/examples/react/hello_react.jsx +0 -26
  129. data/lib/install/examples/react/tsconfig.json +0 -21
  130. data/lib/install/examples/stimulus/application.js +0 -1
  131. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  132. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  133. data/lib/install/examples/svelte/app.svelte +0 -11
  134. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  135. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  136. data/lib/install/examples/typescript/tsconfig.json +0 -24
  137. data/lib/install/examples/vue/hello_vue.js +0 -72
  138. data/lib/install/loaders/coffee.js +0 -6
  139. data/lib/install/loaders/elm.js +0 -25
  140. data/lib/install/loaders/erb.js +0 -11
  141. data/lib/install/loaders/svelte.js +0 -9
  142. data/lib/install/loaders/vue.js +0 -6
  143. data/lib/install/react.rb +0 -18
  144. data/lib/install/stimulus.rb +0 -12
  145. data/lib/install/svelte.rb +0 -29
  146. data/lib/install/typescript.rb +0 -42
  147. data/lib/install/vue.rb +0 -49
  148. data/lib/tasks/installers.rake +0 -42
  149. data/package/config_types/__tests__/config_list.js +0 -118
  150. data/package/config_types/__tests__/config_object.js +0 -43
  151. data/package/config_types/config_list.js +0 -75
  152. data/package/config_types/config_object.js +0 -55
  153. data/package/config_types/index.js +0 -7
  154. data/package/rules/module.css.js +0 -3
  155. data/package/rules/module.sass.js +0 -8
  156. data/package/rules/node_modules.js +0 -24
  157. data/package/utils/__tests__/deep_assign.js +0 -32
  158. data/package/utils/__tests__/deep_merge.js +0 -10
  159. data/package/utils/__tests__/get_style_rule.js +0 -65
  160. data/package/utils/__tests__/objectify.js +0 -9
  161. data/package/utils/deep_assign.js +0 -22
  162. data/package/utils/deep_merge.js +0 -22
  163. data/package/utils/objectify.js +0 -3
@@ -0,0 +1,3 @@
1
+ const { resolve } = require('path')
2
+
3
+ module.exports = process.env.WEBPACKER_CONFIG || resolve('config', 'webpacker.yml')
@@ -1,13 +1,16 @@
1
- const { resolve } = require('path')
2
1
  const { safeLoad } = require('js-yaml')
3
2
  const { readFileSync } = require('fs')
4
3
 
5
4
  const NODE_ENVIRONMENTS = ['development', 'production', 'test']
6
5
  const DEFAULT = 'production'
7
- const configPath = resolve('config', 'webpacker.yml')
6
+ const configPath = require('./configPath')
8
7
 
9
8
  const railsEnv = process.env.RAILS_ENV
10
- const nodeEnv = process.env.NODE_ENV
9
+ const rawNodeEnv = process.env.NODE_ENV
10
+ const nodeEnv
11
+ = rawNodeEnv && NODE_ENVIRONMENTS.includes(rawNodeEnv) ? rawNodeEnv : DEFAULT
12
+ const isProduction = nodeEnv === 'production'
13
+ const isDevelopment = nodeEnv === 'development'
11
14
 
12
15
  const config = safeLoad(readFileSync(configPath), 'utf8')
13
16
  const availableEnvironments = Object.keys(config).join('|')
@@ -15,5 +18,7 @@ const regex = new RegExp(`^(${availableEnvironments})$`, 'g')
15
18
 
16
19
  module.exports = {
17
20
  railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
18
- nodeEnv: nodeEnv && NODE_ENVIRONMENTS.includes(nodeEnv) ? nodeEnv : DEFAULT
21
+ nodeEnv,
22
+ isProduction,
23
+ isDevelopment
19
24
  }
@@ -9,76 +9,61 @@ chdirTestApp()
9
9
 
10
10
  const { resolve } = require('path')
11
11
  const rules = require('../../rules')
12
- const { ConfigList } = require('../../config_types')
13
- const Environment = require('../base')
12
+ const baseConfig = require('../base')
14
13
 
15
- describe('Environment', () => {
14
+ describe('Base config', () => {
16
15
  afterAll(chdirCwd)
17
16
 
18
- let environment
19
-
20
- describe('toWebpackConfig', () => {
21
- beforeEach(() => {
22
- environment = new Environment()
23
- })
24
-
17
+ describe('config', () => {
25
18
  test('should return entry', () => {
26
- const config = environment.toWebpackConfig()
27
- expect(config.entry.application).toEqual(
19
+ expect(baseConfig.entry.application).toEqual(
28
20
  resolve('app', 'javascript', 'packs', 'application.js')
29
21
  )
30
22
  })
31
23
 
32
24
  test('should return multi file entry points', () => {
33
- const config = environment.toWebpackConfig()
34
- expect(config.entry.multi_entry.sort()).toEqual(
35
- [
36
- resolve('app', 'javascript', 'packs', 'multi_entry.css'),
37
- resolve('app', 'javascript', 'packs', 'multi_entry.js')
38
- ]
39
- )
25
+ expect(baseConfig.entry.multi_entry.sort()).toEqual([
26
+ resolve('app', 'javascript', 'packs', 'multi_entry.css'),
27
+ resolve('app', 'javascript', 'packs', 'multi_entry.js')
28
+ ])
40
29
  })
41
30
 
42
31
  test('should return output', () => {
43
- const config = environment.toWebpackConfig()
44
- expect(config.output.filename).toEqual('js/[name]-[contenthash].js')
45
- expect(config.output.chunkFilename).toEqual('js/[name]-[contenthash].chunk.js')
32
+ expect(baseConfig.output.filename).toEqual('js/[name]-[contenthash].js')
33
+ expect(baseConfig.output.chunkFilename).toEqual(
34
+ 'js/[name]-[contenthash].chunk.js'
35
+ )
46
36
  })
47
37
 
48
38
  test('should return default loader rules for each file in config/loaders', () => {
49
- const config = environment.toWebpackConfig()
50
39
  const defaultRules = Object.keys(rules)
51
- const configRules = config.module.rules
40
+ const configRules = baseConfig.module.rules
52
41
 
53
- expect(defaultRules.length).toEqual(7)
54
- expect(configRules.length).toEqual(8)
42
+ expect(defaultRules.length).toEqual(3)
43
+ expect(configRules.length).toEqual(3)
55
44
  })
56
45
 
57
46
  test('should return default plugins', () => {
58
- const config = environment.toWebpackConfig()
59
- expect(config.plugins.length).toEqual(4)
47
+ expect(baseConfig.plugins.length).toEqual(4)
60
48
  })
61
49
 
62
50
  test('should return default resolveLoader', () => {
63
- const config = environment.toWebpackConfig()
64
- expect(config.resolveLoader.modules).toEqual(['node_modules'])
51
+ expect(baseConfig.resolveLoader.modules).toEqual(['node_modules'])
65
52
  })
66
53
 
67
54
  test('should return default resolve.modules with additions', () => {
68
- const config = environment.toWebpackConfig()
69
- expect(config.resolve.modules).toEqual([
55
+ expect(baseConfig.resolve.modules).toEqual([
70
56
  resolve('app', 'javascript'),
71
57
  resolve('app/assets'),
72
58
  resolve('/etc/yarn'),
59
+ resolve('some.config.js'),
60
+ resolve('app/elm'),
73
61
  'node_modules'
74
62
  ])
75
63
  })
76
64
 
77
65
  test('returns plugins property as Array', () => {
78
- const config = environment.toWebpackConfig()
79
-
80
- expect(config.plugins).toBeInstanceOf(Array)
81
- expect(config.plugins).not.toBeInstanceOf(ConfigList)
66
+ expect(baseConfig.plugins).toBeInstanceOf(Array)
82
67
  })
83
68
  })
84
69
  })
@@ -1,177 +1,116 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
- const {
5
- basename, dirname, join, relative, resolve
6
- } = require('path')
7
- const { sync } = require('glob')
4
+ const { basename, dirname, join, relative, resolve } = require('path')
8
5
  const extname = require('path-complete-extname')
9
-
10
- const webpack = require('webpack')
11
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
12
- const WebpackAssetsManifest = require('webpack-assets-manifest')
13
- const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
14
6
  const PnpWebpackPlugin = require('pnp-webpack-plugin')
15
-
16
- const { isNotObject, prettyPrint } = require('../utils/helpers')
17
- const deepMerge = require('../utils/deep_merge')
18
-
19
- const { ConfigList, ConfigObject } = require('../config_types')
7
+ const { sync } = require('glob')
8
+ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
9
+ const WebpackAssetsManifest = require('webpack-assets-manifest')
10
+ const webpack = require('webpack')
20
11
  const rules = require('../rules')
21
12
  const config = require('../config')
22
-
23
- const getLoaderList = () => {
24
- const result = new ConfigList()
25
- Object.keys(rules).forEach((key) => result.append(key, rules[key]))
26
- return result
27
- }
28
-
29
- const getPluginList = () => {
30
- const result = new ConfigList()
31
- result.append(
32
- 'Environment',
33
- new webpack.EnvironmentPlugin(JSON.parse(JSON.stringify(process.env)))
34
- )
35
- result.append('CaseSensitivePaths', new CaseSensitivePathsPlugin())
36
- result.append(
37
- 'MiniCssExtract',
38
- new MiniCssExtractPlugin({
39
- filename: 'css/[name]-[contenthash:8].css',
40
- chunkFilename: 'css/[name]-[contenthash:8].chunk.css'
41
- })
42
- )
43
- result.append(
44
- 'Manifest',
45
- new WebpackAssetsManifest({
46
- integrity: false,
47
- entrypoints: true,
48
- writeToDisk: true,
49
- publicPath: config.publicPathWithoutCDN
50
- })
51
- )
52
- return result
53
- }
54
-
55
- const getExtensionsGlob = () => {
56
- const { extensions } = config
57
- return extensions.length === 1 ? `**/*${extensions[0]}` : `**/*{${extensions.join(',')}}`
58
- }
13
+ const { isDevelopment } = require('../env')
59
14
 
60
15
  const getEntryObject = () => {
61
- const result = new ConfigObject()
62
- const glob = getExtensionsGlob()
16
+ const entries = {}
63
17
  const rootPath = join(config.source_path, config.source_entry_path)
64
- const paths = sync(join(rootPath, glob))
65
- paths.forEach((path) => {
18
+
19
+ sync(`${rootPath}/**/*.*`).forEach((path) => {
66
20
  const namespace = relative(join(rootPath), dirname(path))
67
21
  const name = join(namespace, basename(path, extname(path)))
68
22
  let assetPaths = resolve(path)
69
23
 
70
24
  // Allows for multiple filetypes per entry (https://webpack.js.org/guides/entry-advanced/)
71
25
  // Transforms the config object value to an array with all values under the same name
72
- let previousPaths = result.get(name)
26
+ let previousPaths = entries[name]
73
27
  if (previousPaths) {
74
- previousPaths = Array.isArray(previousPaths) ? previousPaths : [previousPaths]
28
+ previousPaths = Array.isArray(previousPaths)
29
+ ? previousPaths
30
+ : [previousPaths]
75
31
  previousPaths.push(assetPaths)
76
32
  assetPaths = previousPaths
77
33
  }
78
34
 
79
- result.set(name, assetPaths)
35
+ entries[name] = assetPaths
80
36
  })
81
- return result
37
+
38
+ return entries
82
39
  }
83
40
 
84
41
  const getModulePaths = () => {
85
- const result = new ConfigList()
86
- result.append('source', resolve(config.source_path))
87
- if (config.resolved_paths) {
88
- config.resolved_paths.forEach((path) => result.append(path, resolve(path)))
42
+ const result = [resolve(config.source_path)]
43
+
44
+ if (config.additional_paths) {
45
+ config.additional_paths.forEach((path) => result.push(resolve(path)))
89
46
  }
90
- result.append('node_modules', 'node_modules')
47
+ result.push('node_modules')
48
+
91
49
  return result
92
50
  }
93
51
 
94
- const getBaseConfig = () => new ConfigObject({
52
+ const getPlugins = () => {
53
+ const plugins = [
54
+ new webpack.EnvironmentPlugin(process.env),
55
+ PnpWebpackPlugin,
56
+ new CaseSensitivePathsPlugin(),
57
+ new WebpackAssetsManifest({
58
+ entrypoints: true,
59
+ writeToDisk: true,
60
+ output: 'manifest.json',
61
+ entrypointsUseAssets: true,
62
+ publicPath: true
63
+ })
64
+ ]
65
+
66
+ try {
67
+ if (require.resolve('css-loader')) {
68
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
69
+ plugins.push(
70
+ new MiniCssExtractPlugin({
71
+ filename: isDevelopment ? '[name].css' : '[name].[contenthash:8].css',
72
+ chunkFilename: isDevelopment ? '[id].css' : '[id].[contenthash:8].css'
73
+ })
74
+ )
75
+ }
76
+ } catch (e) {
77
+ /* Work out what to print here */
78
+ }
79
+
80
+ return plugins
81
+ }
82
+
83
+ module.exports = {
95
84
  mode: 'production',
96
85
  output: {
97
86
  filename: 'js/[name]-[contenthash].js',
98
87
  chunkFilename: 'js/[name]-[contenthash].chunk.js',
99
88
  hotUpdateChunkFilename: 'js/[id]-[hash].hot-update.js',
89
+ assetModuleFilename: 'static/[hash][ext][query]',
100
90
  path: config.outputPath,
101
91
  publicPath: config.publicPath
102
92
  },
103
-
93
+ entry: getEntryObject(),
104
94
  resolve: {
105
- extensions: config.extensions,
106
- plugins: [PnpWebpackPlugin]
95
+ extensions: ['.js', '.mjs', '.ts'],
96
+ modules: getModulePaths()
107
97
  },
108
98
 
99
+ plugins: getPlugins(),
100
+
109
101
  resolveLoader: {
110
102
  modules: ['node_modules'],
111
103
  plugins: [PnpWebpackPlugin.moduleLoader(module)]
112
104
  },
113
105
 
114
- node: {
115
- dgram: 'empty',
116
- fs: 'empty',
117
- net: 'empty',
118
- tls: 'empty',
119
- child_process: 'empty'
120
- }
121
- })
122
-
123
- module.exports = class Base {
124
- constructor() {
125
- this.loaders = getLoaderList()
126
- this.plugins = getPluginList()
127
- this.config = getBaseConfig()
128
- this.entry = getEntryObject()
129
- this.resolvedModules = getModulePaths()
130
- }
131
-
132
- splitChunks(callback = null) {
133
- let appConfig = {}
134
- const defaultConfig = {
135
- optimization: {
136
- // Split vendor and common chunks
137
- // https://twitter.com/wSokra/status/969633336732905474
138
- splitChunks: {
139
- chunks: 'all',
140
- name: false
141
- },
142
- // Separate runtime chunk to enable long term caching
143
- // https://twitter.com/wSokra/status/969679223278505985
144
- runtimeChunk: true
145
- }
146
- }
147
-
148
- if (callback) {
149
- appConfig = callback(defaultConfig)
150
- if (isNotObject(appConfig)) {
151
- throw new Error(`
152
- ${prettyPrint(appConfig)} is not a valid splitChunks configuration.
153
- See https://webpack.js.org/plugins/split-chunks-plugin/#configuration
154
- `)
155
- }
156
- }
106
+ optimization: {
107
+ splitChunks: { chunks: 'all' },
157
108
 
158
- return this.config.merge(deepMerge(defaultConfig, appConfig))
159
- }
160
-
161
- toWebpackConfig() {
162
- return this.config.merge({
163
- entry: this.entry.toObject(),
164
-
165
- module: {
166
- strictExportPresence: true,
167
- rules: [{ parser: { requireEnsure: false } }, ...this.loaders.values()]
168
- },
169
-
170
- plugins: this.plugins.values(),
109
+ runtimeChunk: { name: (entrypoint) => `runtime-${entrypoint.name}` }
110
+ },
171
111
 
172
- resolve: {
173
- modules: this.resolvedModules.values()
174
- }
175
- })
112
+ module: {
113
+ strictExportPresence: true,
114
+ rules
176
115
  }
177
116
  }
@@ -1,47 +1,54 @@
1
+ const { merge } = require('webpack-merge')
1
2
  const webpack = require('webpack')
2
- const Base = require('./base')
3
+
4
+ const baseConfig = require('./base')
3
5
  const devServer = require('../dev_server')
4
- const { outputPath: contentBase, publicPath } = require('../config')
5
6
 
6
- module.exports = class extends Base {
7
- constructor() {
8
- super()
7
+ const { outputPath: contentBase, publicPath } = require('../config')
9
8
 
10
- if (devServer.hmr) {
11
- this.plugins.append('HotModuleReplacement', new webpack.HotModuleReplacementPlugin())
12
- this.config.output.filename = '[name]-[hash].js'
13
- }
9
+ let devConfig = {
10
+ mode: 'development',
11
+ devtool: 'cheap-module-source-map'
12
+ }
14
13
 
15
- this.config.merge({
16
- mode: 'development',
17
- devtool: 'cheap-module-source-map',
18
- devServer: {
19
- clientLogLevel: 'none',
20
- compress: devServer.compress,
21
- quiet: devServer.quiet,
22
- disableHostCheck: devServer.disable_host_check,
23
- host: devServer.host,
24
- port: devServer.port,
25
- https: devServer.https,
26
- hot: devServer.hmr,
27
- contentBase,
28
- inline: devServer.inline,
29
- useLocalIp: devServer.use_local_ip,
30
- public: devServer.public,
31
- publicPath,
32
- historyApiFallback: {
33
- disableDotRule: true
34
- },
35
- headers: devServer.headers,
36
- overlay: devServer.overlay,
37
- stats: {
38
- entrypoints: false,
39
- errorDetails: true,
40
- modules: false,
41
- moduleTrace: false
42
- },
43
- watchOptions: devServer.watch_options
44
- }
14
+ if (
15
+ process.env.WEBPACK_DEV_SERVER &&
16
+ process.env.WEBPACK_DEV_SERVER !== 'undefined'
17
+ ) {
18
+ if (devServer.hmr) {
19
+ devConfig = merge(devConfig, {
20
+ output: { filename: '[name]-[hash].js' },
21
+ plugins: [new webpack.HotModuleReplacementPlugin()]
45
22
  })
46
23
  }
24
+
25
+ devConfig = merge(devConfig, {
26
+ devServer: {
27
+ clientLogLevel: 'none',
28
+ compress: devServer.compress,
29
+ quiet: devServer.quiet,
30
+ disableHostCheck: devServer.disable_host_check,
31
+ host: devServer.host,
32
+ port: devServer.port,
33
+ https: devServer.https,
34
+ hot: devServer.hmr,
35
+ contentBase,
36
+ inline: devServer.inline,
37
+ useLocalIp: devServer.use_local_ip,
38
+ public: devServer.public,
39
+ publicPath,
40
+ historyApiFallback: { disableDotRule: true },
41
+ headers: devServer.headers,
42
+ overlay: devServer.overlay,
43
+ stats: {
44
+ entrypoints: false,
45
+ errorDetails: true,
46
+ modules: false,
47
+ moduleTrace: false
48
+ },
49
+ watchOptions: devServer.watch_options
50
+ }
51
+ })
47
52
  }
53
+
54
+ module.exports = merge(baseConfig, devConfig)