webpacker 6.0.0.beta.2 → 6.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -18
  3. data/Gemfile.lock +1 -1
  4. data/README.md +96 -219
  5. data/docs/assets.md +135 -0
  6. data/docs/cloud9.md +310 -0
  7. data/docs/css.md +303 -0
  8. data/docs/deployment.md +148 -0
  9. data/docs/docker.md +68 -0
  10. data/docs/engines.md +213 -0
  11. data/docs/env.md +68 -0
  12. data/docs/es6.md +72 -0
  13. data/docs/folder-structure.md +66 -0
  14. data/docs/integrations.md +220 -0
  15. data/docs/misc.md +23 -0
  16. data/docs/props.md +187 -0
  17. data/docs/react.md +183 -0
  18. data/docs/target.md +22 -0
  19. data/docs/testing.md +147 -0
  20. data/docs/troubleshooting.md +158 -0
  21. data/docs/typescript.md +190 -0
  22. data/docs/v4-upgrade.md +142 -0
  23. data/docs/webpack-dev-server.md +94 -0
  24. data/docs/webpack.md +315 -0
  25. data/docs/yarn.md +23 -0
  26. data/lib/install/examples/vue3/app.vue +27 -0
  27. data/lib/install/examples/vue3/hello_vue.js +15 -0
  28. data/lib/install/javascript/packs/application.js +1 -3
  29. data/lib/webpacker/compiler.rb +2 -8
  30. data/lib/webpacker/version.rb +1 -1
  31. data/package.json +1 -1
  32. data/package/babel/preset-react.js +62 -0
  33. data/package/babel/preset.js +13 -24
  34. data/package/environments/__tests__/base.js +1 -1
  35. data/package/environments/base.js +19 -19
  36. data/package/environments/production.js +30 -28
  37. data/package/index.js +2 -7
  38. data/package/rules/coffee.js +5 -5
  39. data/package/rules/erb.js +3 -5
  40. data/package/rules/file.js +3 -5
  41. data/package/rules/index.js +17 -9
  42. data/package/rules/less.js +10 -14
  43. data/package/rules/sass.js +9 -13
  44. data/package/rules/svg.js +23 -0
  45. data/package/utils/get_style_rule.js +31 -27
  46. data/package/utils/helpers.js +0 -23
  47. metadata +29 -7
  48. data/6_0_upgrade.md +0 -43
  49. data/package/rules/raw.js +0 -5
  50. data/package/rules/stylus.js +0 -26
@@ -1,6 +1,6 @@
1
- const { canProcess } = require('../utils/helpers')
2
-
3
- module.exports = canProcess('coffee-loader', (resolvedPath) => ({
1
+ module.exports = {
4
2
  test: /\.coffee(\.erb)?$/,
5
- use: [{ loader: resolvedPath }]
6
- }))
3
+ use: [
4
+ { loader: require.resolve('coffee-loader') }
5
+ ]
6
+ }
@@ -1,15 +1,13 @@
1
- const { canProcess } = require('../utils/helpers')
2
-
3
1
  const runner = /^win/.test(process.platform) ? 'ruby ' : ''
4
2
 
5
- module.exports = canProcess('rails-erb-loader', (resolvedPath) => ({
3
+ module.exports = {
6
4
  test: /\.erb$/,
7
5
  enforce: 'pre',
8
6
  exclude: /node_modules/,
9
7
  use: [
10
8
  {
11
- loader: resolvedPath,
9
+ loader: require.resolve('rails-erb-loader'),
12
10
  options: { runner: `${runner}bin/rails runner` }
13
11
  }
14
12
  ]
15
- }))
13
+ }
@@ -13,11 +13,9 @@ module.exports = {
13
13
  /\.ttf$/,
14
14
  /\.woff$/,
15
15
  /\.woff2$/,
16
- /\.svg$/
16
+ /\.html$/,
17
+ /\.json$/
17
18
  ],
18
19
  exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
19
- type: 'asset/resource',
20
- generator: {
21
- filename: 'media/images/[hash][ext][query]'
22
- }
20
+ type: 'asset/resource'
23
21
  }
@@ -1,16 +1,24 @@
1
1
  /* eslint global-require: 0 */
2
2
  /* eslint import/no-dynamic-require: 0 */
3
3
 
4
+ const load = (name) => {
5
+ try {
6
+ return require(`./${name}`)
7
+ } catch (e) {
8
+ return null
9
+ }
10
+ }
11
+
4
12
  const rules = {
5
- raw: require('./raw'),
6
- file: require('./file'),
7
- css: require('./css'),
8
- sass: require('./sass'),
9
- babel: require('./babel'),
10
- erb: require('./erb'),
11
- coffee: require('./coffee'),
12
- less: require('./less'),
13
- stylus: require('./stylus')
13
+ file: load('file'),
14
+ svg: load('svg'),
15
+ css: load('css'),
16
+ sass: load('sass'),
17
+ babel: load('babel'),
18
+ erb: load('erb'),
19
+ coffee: load('coffee'),
20
+ html: load('html'),
21
+ less: load('less')
14
22
  }
15
23
 
16
24
  module.exports = Object.keys(rules)
@@ -1,22 +1,18 @@
1
1
  const path = require('path')
2
- const { canProcess } = require('../utils/helpers')
3
2
  const getStyleRule = require('../utils/get_style_rule')
4
-
5
3
  const {
6
4
  additional_paths: paths,
7
5
  source_path: sourcePath
8
6
  } = require('../config')
9
7
 
10
- module.exports = canProcess('less-loader', (resolvedPath) =>
11
- getStyleRule(/\.(less)(\.erb)?$/i, [
12
- {
13
- loader: resolvedPath,
14
- options: {
15
- lessOptions: {
16
- paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
17
- },
18
- sourceMap: true
19
- }
8
+ module.exports = getStyleRule(/\.(less)(\.erb)?$/i, [
9
+ {
10
+ loader: require.resolve('less-loader'),
11
+ options: {
12
+ lessOptions: {
13
+ paths: [path.resolve(__dirname, 'node_modules'), sourcePath, ...paths]
14
+ },
15
+ sourceMap: true
20
16
  }
21
- ])
22
- )
17
+ }
18
+ ])
@@ -1,17 +1,13 @@
1
- /* eslint global-require: 0 */
2
-
1
+ const sass = require('sass')
3
2
  const getStyleRule = require('../utils/get_style_rule')
4
- const { canProcess } = require('../utils/helpers')
5
3
  const { additional_paths: includePaths } = require('../config')
6
4
 
7
- module.exports = canProcess('sass-loader', (resolvedPath) =>
8
- getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
9
- {
10
- loader: resolvedPath,
11
- options: {
12
- sassOptions: { includePaths },
13
- implementation: require('sass')
14
- }
5
+ module.exports = getStyleRule(/\.(scss|sass)(\.erb)?$/i, [
6
+ {
7
+ loader: require.resolve('sass-loader'),
8
+ options: {
9
+ sassOptions: { includePaths },
10
+ implementation: sass
15
11
  }
16
- ])
17
- )
12
+ }
13
+ ])
@@ -0,0 +1,23 @@
1
+ /* eslint global-require: 0 */
2
+ /* eslint import/no-dynamic-require: 0 */
3
+
4
+ module.exports = {
5
+ test: /\.svg$/i,
6
+ type: 'asset/inline',
7
+ generator: {
8
+ dataUrl: (content) => {
9
+ let optimisedContent = content
10
+
11
+ try {
12
+ if (require.resolve('mini-svg-data-uri')) {
13
+ const svgToMiniDataURI = require('mini-svg-data-uri')
14
+ optimisedContent = svgToMiniDataURI(content.toString())
15
+ }
16
+ } catch (e) {
17
+ /* Work out what to print here */
18
+ }
19
+
20
+ return optimisedContent
21
+ }
22
+ }
23
+ }
@@ -1,35 +1,39 @@
1
- /* eslint global-require: 0 */
1
+ const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2
2
 
3
- const { canProcess, moduleExists } = require('./helpers')
4
-
5
- const getStyleRule = (test, preprocessors = []) => {
6
- if (moduleExists('css-loader')) {
7
- const tryPostcss = () =>
8
- canProcess('postcss-loader', (loaderPath) => ({
9
- loader: loaderPath,
3
+ const tryPostcss = () => {
4
+ let postcssLoader = false
5
+ try {
6
+ if (require.resolve('postcss-loader')) {
7
+ postcssLoader = {
8
+ loader: require.resolve('postcss-loader'),
10
9
  options: { sourceMap: true }
11
- }))
12
-
13
- const use = [
14
- { loader: require('mini-css-extract-plugin').loader },
15
- {
16
- loader: require.resolve('css-loader'),
17
- options: {
18
- sourceMap: true,
19
- importLoaders: 2
20
- }
21
- },
22
- tryPostcss(),
23
- ...preprocessors
24
- ].filter(Boolean)
25
-
26
- return {
27
- test,
28
- use
10
+ }
29
11
  }
12
+ } catch (e) {
13
+ /* Work out what to print here */
30
14
  }
31
15
 
32
- return null
16
+ return postcssLoader
17
+ }
18
+
19
+ const getStyleRule = (test, preprocessors = []) => {
20
+ const use = [
21
+ { loader: MiniCssExtractPlugin.loader },
22
+ {
23
+ loader: require.resolve('css-loader'),
24
+ options: {
25
+ sourceMap: true,
26
+ importLoaders: 2
27
+ }
28
+ },
29
+ tryPostcss(),
30
+ ...preprocessors
31
+ ].filter(Boolean)
32
+
33
+ return {
34
+ test,
35
+ use
36
+ }
33
37
  }
34
38
 
35
39
  module.exports = getStyleRule
@@ -16,34 +16,11 @@ const resetEnv = () => {
16
16
 
17
17
  const ensureTrailingSlash = (path) => (path.endsWith('/') ? path : `${path}/`)
18
18
 
19
- const moduleExists = (packageName) => {
20
- try {
21
- return require.resolve(packageName)
22
- } catch (e) {
23
- if (e.code !== 'MODULE_NOT_FOUND') {
24
- throw e
25
- }
26
- return null
27
- }
28
- }
29
-
30
- const canProcess = (rule, fn) => {
31
- const modulePath = moduleExists(rule)
32
-
33
- if (modulePath) {
34
- return fn(modulePath)
35
- }
36
-
37
- return null
38
- }
39
-
40
19
  module.exports = {
41
20
  chdirTestApp,
42
21
  chdirCwd,
43
22
  isArray,
44
23
  isBoolean,
45
24
  ensureTrailingSlash,
46
- canProcess,
47
- moduleExists,
48
25
  resetEnv
49
26
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpacker
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0.beta.2
4
+ version: 6.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-24 00:00:00.000000000 Z
12
+ date: 2020-12-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -126,7 +126,6 @@ files:
126
126
  - ".gitignore"
127
127
  - ".node-version"
128
128
  - ".rubocop.yml"
129
- - 6_0_upgrade.md
130
129
  - CHANGELOG.md
131
130
  - CONTRIBUTING.md
132
131
  - Gemfile
@@ -134,6 +133,27 @@ files:
134
133
  - MIT-LICENSE
135
134
  - README.md
136
135
  - Rakefile
136
+ - docs/assets.md
137
+ - docs/cloud9.md
138
+ - docs/css.md
139
+ - docs/deployment.md
140
+ - docs/docker.md
141
+ - docs/engines.md
142
+ - docs/env.md
143
+ - docs/es6.md
144
+ - docs/folder-structure.md
145
+ - docs/integrations.md
146
+ - docs/misc.md
147
+ - docs/props.md
148
+ - docs/react.md
149
+ - docs/target.md
150
+ - docs/testing.md
151
+ - docs/troubleshooting.md
152
+ - docs/typescript.md
153
+ - docs/v4-upgrade.md
154
+ - docs/webpack-dev-server.md
155
+ - docs/webpack.md
156
+ - docs/yarn.md
137
157
  - gemfiles/Gemfile-rails-edge
138
158
  - gemfiles/Gemfile-rails.5.2.x
139
159
  - gemfiles/Gemfile-rails.6.0.x
@@ -145,6 +165,8 @@ files:
145
165
  - lib/install/config/webpack/production.js
146
166
  - lib/install/config/webpack/test.js
147
167
  - lib/install/config/webpacker.yml
168
+ - lib/install/examples/vue3/app.vue
169
+ - lib/install/examples/vue3/hello_vue.js
148
170
  - lib/install/javascript/packs/application.css
149
171
  - lib/install/javascript/packs/application.js
150
172
  - lib/install/template.rb
@@ -183,6 +205,7 @@ files:
183
205
  - package/__tests__/production.js
184
206
  - package/__tests__/staging.js
185
207
  - package/__tests__/test.js
208
+ - package/babel/preset-react.js
186
209
  - package/babel/preset.js
187
210
  - package/config.js
188
211
  - package/configPath.js
@@ -201,9 +224,8 @@ files:
201
224
  - package/rules/file.js
202
225
  - package/rules/index.js
203
226
  - package/rules/less.js
204
- - package/rules/raw.js
205
227
  - package/rules/sass.js
206
- - package/rules/stylus.js
228
+ - package/rules/svg.js
207
229
  - package/utils/get_style_rule.js
208
230
  - package/utils/helpers.js
209
231
  - test/command_test.rb
@@ -250,8 +272,8 @@ homepage: https://github.com/rails/webpacker
250
272
  licenses:
251
273
  - MIT
252
274
  metadata:
253
- source_code_uri: https://github.com/rails/webpacker/tree/v6.0.0.beta.2
254
- changelog_uri: https://github.com/rails/webpacker/blob/v6.0.0.beta.2/CHANGELOG.md
275
+ source_code_uri: https://github.com/rails/webpacker/tree/v6.0.0.pre.1
276
+ changelog_uri: https://github.com/rails/webpacker/blob/v6.0.0.pre.1/CHANGELOG.md
255
277
  post_install_message:
256
278
  rdoc_options: []
257
279
  require_paths:
@@ -1,43 +0,0 @@
1
- # To webpacker v6 from v5
2
-
3
- This guide aims to help you migrating to webpacker 6. If you are using
4
- vanilla webpacker install then hopefully, the upgrade should be really
5
- straightforward.
6
-
7
- ## Preparation
8
-
9
- - Rename `config/webpack` to `config/webpack_old`
10
- - Rename `config/webpacker.yml` to `config/webpacker_old.yml`
11
- - Upgrade webpacker
12
-
13
- ```ruby
14
- # Gemfile
15
- gem 'webpacker', '~> 6.x'
16
- ```
17
-
18
- ```
19
- bundle
20
- ```
21
-
22
- ```bash
23
- yarn add @rails/webpacker@next
24
- ```
25
-
26
- ```bash
27
- bundle exec rails webpacker:install
28
- ```
29
-
30
- - Change `javascript_pack_tag` and `stylesheet_pack_tag` to `javascript_packs_with_chunks_tag` and
31
- `stylesheet_packs_with_chunks_tag`
32
-
33
- - If you are using any integrations like css, react or typescript. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.0
34
-
35
- - Copy over any custom webpack config from `config/webpack_old`
36
-
37
- ```js
38
- // config/webpack/base.js
39
- const { webpackConfig, merge } = require('@rails/webpacker')
40
- const customConfig = require('./custom')
41
-
42
- module.exports = merge(webpackConfig, customConfig)
43
- ```
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- test: [/\.html$/],
3
- exclude: [/\.(js|mjs|jsx|ts|tsx)$/],
4
- type: 'asset/source'
5
- }
@@ -1,26 +0,0 @@
1
- const path = require('path')
2
- const { canProcess } = require('../utils/helpers')
3
- const getStyleRule = require('../utils/get_style_rule')
4
-
5
- const {
6
- additional_paths: paths,
7
- source_path: sourcePath
8
- } = require('../config')
9
-
10
- module.exports = canProcess('stylus-loader', (resolvedPath) =>
11
- getStyleRule(/\.(styl)(\.erb)?$/i, [
12
- {
13
- loader: resolvedPath,
14
- options: {
15
- stylusOptions: {
16
- include: [
17
- path.resolve(__dirname, 'node_modules'),
18
- sourcePath,
19
- ...paths
20
- ]
21
- },
22
- sourceMap: true
23
- }
24
- }
25
- ])
26
- )