webpacker 3.6.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.node-version +1 -0
- data/.travis.yml +12 -4
- data/CHANGELOG.md +240 -28
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +78 -71
- data/MIT-LICENSE +1 -1
- data/README.md +75 -16
- data/docs/assets.md +7 -4
- data/docs/css.md +47 -14
- data/docs/deployment.md +11 -0
- data/docs/engines.md +155 -0
- data/docs/es6.md +5 -5
- data/docs/testing.md +1 -1
- data/docs/troubleshooting.md +4 -4
- data/docs/v4-upgrade.md +132 -0
- data/docs/webpack.md +56 -3
- data/docs/yarn.md +12 -1
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.4.2.x +2 -2
- data/gemfiles/Gemfile-rails.5.0.x +2 -2
- data/gemfiles/Gemfile-rails.5.1.x +2 -2
- data/gemfiles/Gemfile-rails.5.2.x +10 -0
- data/lib/install/bin/webpack +5 -1
- data/lib/install/bin/webpack-dev-server +5 -1
- data/lib/install/coffee.rb +2 -2
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +70 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpacker.yml +26 -0
- data/lib/install/elm.rb +2 -2
- data/lib/install/erb.rb +2 -2
- data/lib/install/examples/react/babel.config.js +83 -0
- data/lib/install/examples/stimulus/application.js +1 -6
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/typescript/tsconfig.json +4 -0
- data/lib/install/examples/vue/hello_vue.js +6 -4
- data/lib/install/javascript/packs/application.js +8 -0
- data/lib/install/loaders/typescript.js +8 -3
- data/lib/install/loaders/vue.js +1 -8
- data/lib/install/react.rb +6 -19
- data/lib/install/template.rb +29 -30
- data/lib/install/typescript.rb +4 -4
- data/lib/install/vue.rb +14 -5
- data/lib/tasks/installers.rake +4 -2
- data/lib/tasks/webpacker/binstubs.rake +3 -2
- data/lib/tasks/webpacker/compile.rake +10 -5
- data/lib/tasks/webpacker/install.rake +3 -2
- data/lib/tasks/webpacker/verify_install.rake +1 -4
- data/lib/tasks/webpacker/yarn_install.rake +1 -1
- data/lib/webpacker/commands.rb +0 -1
- data/lib/webpacker/compiler.rb +17 -13
- data/lib/webpacker/configuration.rb +13 -5
- data/lib/webpacker/dev_server.rb +7 -10
- data/lib/webpacker/dev_server_proxy.rb +13 -6
- data/lib/webpacker/dev_server_runner.rb +13 -6
- data/lib/webpacker/helper.rb +78 -20
- data/lib/webpacker/manifest.rb +64 -21
- data/lib/webpacker/railtie.rb +16 -7
- data/lib/webpacker/runner.rb +3 -3
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +14 -3
- data/package.json +46 -34
- data/package/__tests__/config.js +37 -3
- data/package/__tests__/dev_server.js +15 -0
- data/package/__tests__/production.js +2 -2
- data/package/__tests__/staging.js +3 -3
- data/package/__tests__/test.js +2 -1
- data/package/config.js +21 -9
- data/package/config_types/config_list.js +5 -6
- data/package/dev_server.js +3 -1
- data/package/environments/__tests__/base.js +7 -5
- data/package/environments/base.js +84 -31
- data/package/environments/development.js +6 -2
- data/package/environments/production.js +46 -36
- data/package/rules/babel.js +10 -4
- data/package/rules/file.js +8 -3
- data/package/rules/index.js +7 -2
- data/package/rules/node_modules.js +23 -0
- data/package/utils/__tests__/get_style_rule.js +20 -0
- data/package/utils/deep_merge.js +5 -6
- data/package/utils/get_style_rule.js +29 -42
- data/package/utils/helpers.js +18 -6
- data/package/utils/objectify.js +1 -2
- data/test/compiler_test.rb +15 -3
- data/test/configuration_test.rb +9 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/helper_test.rb +48 -5
- data/test/manifest_test.rb +14 -0
- data/test/rake_tasks_test.rb +34 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +1 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +20 -0
- data/test/test_app/config/webpacker_public_root.yml +19 -0
- data/test/test_app/package.json +13 -0
- data/test/test_app/public/packs/manifest.json +22 -1
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +1 -3
- data/test/webpack_runner_test.rb +51 -0
- data/yarn.lock +4077 -2816
- metadata +28 -6
- data/lib/install/config/.babelrc +0 -18
- data/lib/install/config/.postcssrc.yml +0 -3
- data/lib/install/examples/react/.babelrc +0 -6
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
default: &default
|
|
4
4
|
source_path: app/javascript
|
|
5
5
|
source_entry_path: packs
|
|
6
|
+
public_root_path: public
|
|
6
7
|
public_output_path: packs
|
|
7
8
|
cache_path: tmp/cache/webpacker
|
|
9
|
+
check_yarn_integrity: false
|
|
8
10
|
webpack_compile_output: false
|
|
9
11
|
|
|
10
12
|
# Additional paths webpack should lookup modules
|
|
@@ -14,7 +16,25 @@ default: &default
|
|
|
14
16
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
|
15
17
|
cache_manifest: false
|
|
16
18
|
|
|
19
|
+
# Extract and emit a css file
|
|
20
|
+
extract_css: false
|
|
21
|
+
|
|
22
|
+
static_assets_extensions:
|
|
23
|
+
- .jpg
|
|
24
|
+
- .jpeg
|
|
25
|
+
- .png
|
|
26
|
+
- .gif
|
|
27
|
+
- .tiff
|
|
28
|
+
- .ico
|
|
29
|
+
- .svg
|
|
30
|
+
- .eot
|
|
31
|
+
- .otf
|
|
32
|
+
- .ttf
|
|
33
|
+
- .woff
|
|
34
|
+
- .woff2
|
|
35
|
+
|
|
17
36
|
extensions:
|
|
37
|
+
- .mjs
|
|
18
38
|
- .js
|
|
19
39
|
- .sass
|
|
20
40
|
- .scss
|
|
@@ -32,6 +52,9 @@ development:
|
|
|
32
52
|
<<: *default
|
|
33
53
|
compile: true
|
|
34
54
|
|
|
55
|
+
# Verifies that versions and hashed value of the package contents in the project's package.json
|
|
56
|
+
check_yarn_integrity: true
|
|
57
|
+
|
|
35
58
|
# Reference: https://webpack.js.org/configuration/dev-server/
|
|
36
59
|
dev_server:
|
|
37
60
|
https: false
|
|
@@ -65,5 +88,8 @@ production:
|
|
|
65
88
|
# Production depends on precompilation of packs prior to booting for performance.
|
|
66
89
|
compile: false
|
|
67
90
|
|
|
91
|
+
# Extract and emit a css file
|
|
92
|
+
extract_css: true
|
|
93
|
+
|
|
68
94
|
# Cache manifest.json for performance
|
|
69
95
|
cache_manifest: true
|
data/lib/install/elm.rb
CHANGED
|
@@ -9,7 +9,7 @@ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
|
9
9
|
after: "require('@rails/webpacker')\n"
|
|
10
10
|
|
|
11
11
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
12
|
-
"environment.loaders.
|
|
12
|
+
"environment.loaders.prepend('elm', elm)\n",
|
|
13
13
|
before: "module.exports"
|
|
14
14
|
|
|
15
15
|
say "Copying Elm example entry file to #{Webpacker.config.source_entry_path}"
|
|
@@ -27,7 +27,7 @@ run "yarn run elm init"
|
|
|
27
27
|
run "yarn run elm make"
|
|
28
28
|
|
|
29
29
|
say "Updating webpack paths to include .elm file extension"
|
|
30
|
-
insert_into_file Webpacker.config.config_path, "
|
|
30
|
+
insert_into_file Webpacker.config.config_path, "- .elm\n".indent(4), after: /\s+extensions:\n/
|
|
31
31
|
|
|
32
32
|
say "Updating Elm source location"
|
|
33
33
|
gsub_file "elm.json", /\"\src\"\n/,
|
data/lib/install/erb.rb
CHANGED
|
@@ -9,11 +9,11 @@ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
|
9
9
|
after: "require('@rails/webpacker')\n"
|
|
10
10
|
|
|
11
11
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
12
|
-
"environment.loaders.
|
|
12
|
+
"environment.loaders.prepend('erb', erb)\n",
|
|
13
13
|
before: "module.exports"
|
|
14
14
|
|
|
15
15
|
say "Updating webpack paths to include .erb file extension"
|
|
16
|
-
insert_into_file Webpacker.config.config_path, "
|
|
16
|
+
insert_into_file Webpacker.config.config_path, "- .erb\n".indent(4), after: /\s+extensions:\n/
|
|
17
17
|
|
|
18
18
|
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
|
|
19
19
|
copy_file "#{__dir__}/examples/erb/hello_erb.js.erb",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module.exports = function(api) {
|
|
2
|
+
var validEnv = ['development', 'test', 'production']
|
|
3
|
+
var currentEnv = api.env()
|
|
4
|
+
var isDevelopmentEnv = api.env('development')
|
|
5
|
+
var isProductionEnv = api.env('production')
|
|
6
|
+
var isTestEnv = api.env('test')
|
|
7
|
+
|
|
8
|
+
if (!validEnv.includes(currentEnv)) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
'Please specify a valid `NODE_ENV` or ' +
|
|
11
|
+
'`BABEL_ENV` environment variables. Valid values are "development", ' +
|
|
12
|
+
'"test", and "production". Instead, received: ' +
|
|
13
|
+
JSON.stringify(currentEnv) +
|
|
14
|
+
'.'
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
presets: [
|
|
20
|
+
isTestEnv && [
|
|
21
|
+
require('@babel/preset-env').default,
|
|
22
|
+
{
|
|
23
|
+
targets: {
|
|
24
|
+
node: 'current'
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
(isProductionEnv || isDevelopmentEnv) && [
|
|
29
|
+
require('@babel/preset-env').default,
|
|
30
|
+
{
|
|
31
|
+
forceAllTransforms: true,
|
|
32
|
+
useBuiltIns: 'entry',
|
|
33
|
+
modules: false,
|
|
34
|
+
exclude: ['transform-typeof-symbol']
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
require('@babel/preset-react').default,
|
|
39
|
+
{
|
|
40
|
+
development: isDevelopmentEnv || isTestEnv,
|
|
41
|
+
useBuiltIns: true
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
].filter(Boolean),
|
|
45
|
+
plugins: [
|
|
46
|
+
require('babel-plugin-macros'),
|
|
47
|
+
require('@babel/plugin-syntax-dynamic-import').default,
|
|
48
|
+
isTestEnv && require('babel-plugin-dynamic-import-node'),
|
|
49
|
+
require('@babel/plugin-transform-destructuring').default,
|
|
50
|
+
[
|
|
51
|
+
require('@babel/plugin-proposal-class-properties').default,
|
|
52
|
+
{
|
|
53
|
+
loose: true
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
[
|
|
57
|
+
require('@babel/plugin-proposal-object-rest-spread').default,
|
|
58
|
+
{
|
|
59
|
+
useBuiltIns: true
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
require('@babel/plugin-transform-runtime').default,
|
|
64
|
+
{
|
|
65
|
+
helpers: false,
|
|
66
|
+
regenerator: true
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
require('@babel/plugin-transform-regenerator').default,
|
|
71
|
+
{
|
|
72
|
+
async: false
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
isProductionEnv && [
|
|
76
|
+
require('babel-plugin-transform-react-remove-prop-types').default,
|
|
77
|
+
{
|
|
78
|
+
removeImport: true
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
].filter(Boolean)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { definitionsFromContext } from "stimulus/webpack-helpers"
|
|
3
|
-
|
|
4
|
-
const application = Application.start()
|
|
5
|
-
const context = require.context("controllers", true, /.js$/)
|
|
6
|
-
application.load(definitionsFromContext(context))
|
|
1
|
+
import "controllers"
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Load all the controllers within this directory and all subdirectories.
|
|
2
|
+
// Controller files must be named *_controller.js.
|
|
3
|
+
|
|
4
|
+
import { Application } from "stimulus"
|
|
5
|
+
import { definitionsFromContext } from "stimulus/webpack-helpers"
|
|
6
|
+
|
|
7
|
+
const application = Application.start()
|
|
8
|
+
const context = require.context("controllers", true, /_controller\.js$/)
|
|
9
|
+
application.load(definitionsFromContext(context))
|
|
@@ -48,9 +48,9 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
48
48
|
//
|
|
49
49
|
//
|
|
50
50
|
//
|
|
51
|
-
// If the using turbolinks, install 'vue-turbolinks':
|
|
51
|
+
// If the project is using turbolinks, install 'vue-turbolinks':
|
|
52
52
|
//
|
|
53
|
-
// yarn add
|
|
53
|
+
// yarn add vue-turbolinks
|
|
54
54
|
//
|
|
55
55
|
// Then uncomment the code block below:
|
|
56
56
|
//
|
|
@@ -63,8 +63,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
|
63
63
|
// document.addEventListener('turbolinks:load', () => {
|
|
64
64
|
// const app = new Vue({
|
|
65
65
|
// el: '#hello',
|
|
66
|
-
// data: {
|
|
67
|
-
//
|
|
66
|
+
// data: () => {
|
|
67
|
+
// return {
|
|
68
|
+
// message: "Can you say hello?"
|
|
69
|
+
// }
|
|
68
70
|
// },
|
|
69
71
|
// components: { App }
|
|
70
72
|
// })
|
|
@@ -7,4 +7,12 @@
|
|
|
7
7
|
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
|
8
8
|
// layout file, like app/views/layouts/application.html.erb
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
// Uncomment to copy all static images under ../images to the output folder and reference
|
|
12
|
+
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
|
|
13
|
+
// or the `imagePath` JavaScript helper below.
|
|
14
|
+
//
|
|
15
|
+
// const images = require.context('../images', true)
|
|
16
|
+
// const imagePath = (name) => images(name, true)
|
|
17
|
+
|
|
10
18
|
console.log('Hello World from Webpacker')
|
data/lib/install/loaders/vue.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
const { dev_server: devServer } = require('@rails/webpacker').config
|
|
2
|
-
|
|
3
|
-
const isProduction = process.env.NODE_ENV === 'production'
|
|
4
|
-
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
|
|
5
|
-
const extractCSS = !(inDevServer && (devServer && devServer.hmr)) || isProduction
|
|
6
|
-
|
|
7
1
|
module.exports = {
|
|
8
2
|
test: /\.vue(\.erb)?$/,
|
|
9
3
|
use: [{
|
|
10
|
-
loader: 'vue-loader'
|
|
11
|
-
options: { extractCSS }
|
|
4
|
+
loader: 'vue-loader'
|
|
12
5
|
}]
|
|
13
6
|
}
|
data/lib/install/react.rb
CHANGED
|
@@ -1,31 +1,18 @@
|
|
|
1
1
|
require "webpacker/configuration"
|
|
2
|
+
require "fileutils"
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
replace_babel_config = FileUtils.compare_file(Rails.root.join("babel.config.js"), "#{__dir__}/config/babel.config.js")
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
react_babelrc["presets"] ||= []
|
|
8
|
-
|
|
9
|
-
unless react_babelrc["presets"].include?("react")
|
|
10
|
-
react_babelrc["presets"].push("react")
|
|
11
|
-
say "Copying react preset to your .babelrc file"
|
|
12
|
-
|
|
13
|
-
File.open(babelrc, "w") do |f|
|
|
14
|
-
f.puts JSON.pretty_generate(react_babelrc)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
else
|
|
18
|
-
say "Copying .babelrc to app root directory"
|
|
19
|
-
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
|
|
20
|
-
end
|
|
6
|
+
say "Copying babel.config.js to app root directory"
|
|
7
|
+
copy_file "#{__dir__}/examples/react/babel.config.js", "babel.config.js", force: replace_babel_config
|
|
21
8
|
|
|
22
9
|
say "Copying react example entry file to #{Webpacker.config.source_entry_path}"
|
|
23
10
|
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker.config.source_entry_path}/hello_react.jsx"
|
|
24
11
|
|
|
25
12
|
say "Updating webpack paths to include .jsx file extension"
|
|
26
|
-
insert_into_file Webpacker.config.config_path, "
|
|
13
|
+
insert_into_file Webpacker.config.config_path, "- .jsx\n".indent(4), after: /\s+extensions:\n/
|
|
27
14
|
|
|
28
15
|
say "Installing all react dependencies"
|
|
29
|
-
run "yarn add react react-dom babel
|
|
16
|
+
run "yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types"
|
|
30
17
|
|
|
31
18
|
say "Webpacker now supports react.js 🎉", :green
|
data/lib/install/template.rb
CHANGED
|
@@ -4,47 +4,46 @@ copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
|
|
4
4
|
puts "Copying webpack core config"
|
|
5
5
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
|
6
6
|
|
|
7
|
-
say "Copying .
|
|
8
|
-
copy_file "#{__dir__}/config
|
|
7
|
+
say "Copying postcss.config.js to app root directory"
|
|
8
|
+
copy_file "#{__dir__}/config/postcss.config.js", "postcss.config.js"
|
|
9
9
|
|
|
10
|
-
say "Copying .
|
|
11
|
-
copy_file "#{__dir__}/config
|
|
10
|
+
say "Copying babel.config.js to app root directory"
|
|
11
|
+
copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
|
|
12
12
|
|
|
13
|
-
say "
|
|
14
|
-
|
|
13
|
+
say "Copying .browserslistrc to app root directory"
|
|
14
|
+
copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
say "Adding configurations"
|
|
19
|
-
|
|
20
|
-
check_yarn_integrity_config = ->(value) { <<CONFIG }
|
|
21
|
-
# Verifies that versions and hashed value of the package contents in the project's package.json
|
|
22
|
-
config.webpacker.check_yarn_integrity = #{value}
|
|
23
|
-
CONFIG
|
|
24
|
-
|
|
25
|
-
if Rails::VERSION::MAJOR >= 5
|
|
26
|
-
environment check_yarn_integrity_config.call("true"), env: :development
|
|
27
|
-
environment check_yarn_integrity_config.call("false"), env: :production
|
|
16
|
+
if Dir.exists?(Webpacker.config.source_path)
|
|
17
|
+
say "The JavaScript app source directory already exists"
|
|
28
18
|
else
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
say "Creating JavaScript app source directory"
|
|
20
|
+
directory "#{__dir__}/javascript", Webpacker.config.source_path
|
|
31
21
|
end
|
|
32
22
|
|
|
23
|
+
apply "#{__dir__}/binstubs.rb"
|
|
24
|
+
|
|
33
25
|
if File.exists?(".gitignore")
|
|
34
|
-
append_to_file ".gitignore"
|
|
35
|
-
|
|
36
|
-
/public/packs
|
|
37
|
-
/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
append_to_file ".gitignore" do
|
|
27
|
+
"\n" +
|
|
28
|
+
"/public/packs\n" +
|
|
29
|
+
"/public/packs-test\n" +
|
|
30
|
+
"/node_modules\n" +
|
|
31
|
+
"/yarn-error.log\n" +
|
|
32
|
+
"yarn-debug.log*\n" +
|
|
33
|
+
".yarn-integrity\n"
|
|
34
|
+
end
|
|
41
35
|
end
|
|
42
36
|
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
|
|
38
|
+
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
|
|
39
|
+
run "yarn add @rails/webpacker"
|
|
40
|
+
else
|
|
41
|
+
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
|
|
42
|
+
run "yarn add @rails/webpacker@next"
|
|
43
|
+
end
|
|
45
44
|
|
|
46
45
|
say "Installing dev server for live reloading"
|
|
47
|
-
run "yarn add --dev webpack-dev-server
|
|
46
|
+
run "yarn add --dev webpack-dev-server"
|
|
48
47
|
|
|
49
48
|
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
|
50
49
|
say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
|
data/lib/install/typescript.rb
CHANGED
|
@@ -24,23 +24,23 @@ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
|
24
24
|
after: "require('@rails/webpacker')\n"
|
|
25
25
|
|
|
26
26
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
27
|
-
"environment.loaders.
|
|
27
|
+
"environment.loaders.prepend('typescript', typescript)\n",
|
|
28
28
|
before: "module.exports"
|
|
29
29
|
|
|
30
30
|
say "Copying tsconfig.json to the Rails root directory for typescript"
|
|
31
31
|
copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"
|
|
32
32
|
|
|
33
33
|
say "Updating webpack paths to include .ts file extension"
|
|
34
|
-
insert_into_file Webpacker.config.config_path, "
|
|
34
|
+
insert_into_file Webpacker.config.config_path, "- .ts\n".indent(4), after: /\s+extensions:\n/
|
|
35
35
|
|
|
36
36
|
say "Updating webpack paths to include .tsx file extension"
|
|
37
|
-
insert_into_file Webpacker.config.config_path, "
|
|
37
|
+
insert_into_file Webpacker.config.config_path, "- .tsx\n".indent(4), after: /\s+extensions:\n/
|
|
38
38
|
|
|
39
39
|
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
|
|
40
40
|
copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
|
|
41
41
|
"#{Webpacker.config.source_entry_path}/hello_typescript.ts"
|
|
42
42
|
|
|
43
43
|
say "Installing all typescript dependencies"
|
|
44
|
-
run "yarn add typescript ts-loader
|
|
44
|
+
run "yarn add typescript ts-loader #{additional_packages}"
|
|
45
45
|
|
|
46
46
|
say "Webpacker now supports typescript 🎉", :green
|
data/lib/install/vue.rb
CHANGED
|
@@ -3,17 +3,26 @@ require "webpacker/configuration"
|
|
|
3
3
|
say "Copying vue loader to config/webpack/loaders"
|
|
4
4
|
copy_file "#{__dir__}/loaders/vue.js", Rails.root.join("config/webpack/loaders/vue.js").to_s
|
|
5
5
|
|
|
6
|
-
say "Adding vue loader to config/webpack/environment.js"
|
|
6
|
+
say "Adding vue loader plugin to config/webpack/environment.js"
|
|
7
7
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
8
|
-
"const
|
|
8
|
+
"const { VueLoaderPlugin } = require('vue-loader')\n",
|
|
9
9
|
after: "require('@rails/webpacker')\n"
|
|
10
10
|
|
|
11
11
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
12
|
-
"environment.
|
|
12
|
+
"environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())\n",
|
|
13
|
+
before: "module.exports"
|
|
14
|
+
|
|
15
|
+
say "Adding vue loader to config/webpack/environment.js"
|
|
16
|
+
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
17
|
+
"const vue = require('./loaders/vue')\n",
|
|
18
|
+
after: "require('vue-loader')\n"
|
|
19
|
+
|
|
20
|
+
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
|
21
|
+
"environment.loaders.prepend('vue', vue)\n",
|
|
13
22
|
before: "module.exports"
|
|
14
23
|
|
|
15
24
|
say "Updating webpack paths to include .vue file extension"
|
|
16
|
-
insert_into_file Webpacker.config.config_path, "
|
|
25
|
+
insert_into_file Webpacker.config.config_path, "- .vue\n".indent(4), after: /\s+extensions:\n/
|
|
17
26
|
|
|
18
27
|
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
|
|
19
28
|
copy_file "#{__dir__}/examples/vue/hello_vue.js",
|
|
@@ -24,7 +33,7 @@ copy_file "#{__dir__}/examples/vue/app.vue",
|
|
|
24
33
|
"#{Webpacker.config.source_path}/app.vue"
|
|
25
34
|
|
|
26
35
|
say "Installing all Vue dependencies"
|
|
27
|
-
run "yarn add vue vue-loader
|
|
36
|
+
run "yarn add vue vue-loader vue-template-compiler"
|
|
28
37
|
|
|
29
38
|
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
|
30
39
|
say "You need to enable unsafe-eval rule.", :yellow
|