jetpacker 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +8 -8
- data/.github/workflows/jest.yml +38 -0
- data/.github/workflows/js-lint.yml +39 -0
- data/.github/workflows/rubocop.yml +39 -0
- data/.github/workflows/ruby.yml +70 -0
- data/.node-version +1 -1
- data/.travis.yml +8 -21
- data/CHANGELOG.jetpacker.md +18 -0
- data/CHANGELOG.md +44 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +115 -101
- data/README.md +24 -649
- data/docs/css.md +58 -3
- data/docs/deployment.md +2 -2
- data/docs/docker.md +17 -17
- data/docs/engines.md +13 -0
- data/docs/env.md +0 -2
- data/docs/integrations.md +220 -0
- data/docs/target.md +22 -0
- data/docs/testing.md +2 -3
- data/docs/troubleshooting.md +3 -1
- data/docs/typescript.md +92 -28
- data/docs/webpack-dev-server.md +1 -1
- data/jetpacker.gemspec +6 -5
- data/lib/install/config/babel.config.js +1 -3
- data/lib/install/config/webpacker.yml +11 -6
- data/lib/install/examples/react/tsconfig.json +2 -1
- data/lib/install/examples/typescript/tsconfig.json +2 -1
- data/lib/install/loaders/svelte.js +2 -2
- data/lib/install/template.rb +7 -7
- data/lib/install/typescript.rb +5 -1
- data/lib/jetpacker.rb +1 -0
- data/lib/jetpacker/version.rb +1 -1
- data/lib/tasks/webpacker/check_node.rake +15 -8
- data/lib/tasks/webpacker/check_yarn.rake +17 -10
- data/lib/tasks/webpacker/clean.rake +12 -8
- data/lib/tasks/webpacker/clobber.rake +8 -4
- data/lib/tasks/webpacker/yarn_install.rake +5 -16
- data/lib/webpacker.rb +1 -1
- data/lib/webpacker/commands.rb +33 -9
- data/lib/webpacker/compiler.rb +9 -5
- data/lib/webpacker/configuration.rb +13 -9
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +2 -2
- data/lib/webpacker/helper.rb +37 -18
- data/lib/webpacker/manifest.rb +4 -4
- data/lib/webpacker/railtie.rb +0 -43
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/turbine.rb +36 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +2 -2
- data/package.json +39 -39
- data/package/__tests__/config.js +12 -1
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +14 -1
- data/package/config.js +4 -1
- data/package/configPath.js +3 -0
- data/package/dev_server.js +1 -1
- data/package/env.js +1 -2
- data/package/environments/__tests__/base.js +29 -2
- data/package/environments/base.js +17 -7
- data/package/environments/development.js +39 -37
- data/package/environments/production.js +1 -3
- data/package/rules/babel.js +12 -5
- data/package/rules/file.js +1 -0
- data/package/rules/node_modules.js +1 -3
- data/package/rules/sass.js +7 -1
- data/package/utils/helpers.js +1 -1
- data/test/compiler_test.rb +8 -3
- data/test/configuration_test.rb +8 -7
- data/test/dev_server_runner_test.rb +1 -1
- data/test/helper_test.rb +3 -0
- data/test/manifest_test.rb +37 -6
- data/test/rake_tasks_test.rb +11 -0
- data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
- data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/webpacker.yml +7 -1
- data/test/test_app/public/packs/manifest.json +1 -0
- data/test/webpack_runner_test.rb +1 -1
- data/yarn.lock +3405 -2836
- metadata +38 -16
- data/gemfiles/Gemfile-rails.4.2.x +0 -9
- data/gemfiles/Gemfile-rails.5.0.x +0 -9
- data/gemfiles/Gemfile-rails.5.1.x +0 -9
- data/lib/install/javascript/packs/application.js +0 -18
- data/lib/install/loaders/typescript.js +0 -11
data/docs/troubleshooting.md
CHANGED
@@ -4,11 +4,13 @@
|
|
4
4
|
|
5
5
|
1. Read the error message carefully. The error message will tell you the precise key value
|
6
6
|
that is not matching what Webpack expects.
|
7
|
-
2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug`.
|
7
|
+
2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug-webpacker`.
|
8
8
|
If you have a node debugger installed, you'll see the Chrome debugger for your webpack
|
9
9
|
config. For example, install the Chrome extension [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
|
10
10
|
set the option for the dev tools to open automatically. For more details on debugging,
|
11
11
|
see the official [Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
|
12
|
+
3. Any arguments that you add to bin/webpack get sent to webpack. For example, you can pass `--debug` to switch loaders to debug mode. See [webpack CLI debug options](https://webpack.js.org/api/cli/#debug-options) for more information on the available options.
|
13
|
+
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-webpacker`
|
12
14
|
|
13
15
|
## ENOENT: no such file or directory - node-sass
|
14
16
|
|
data/docs/typescript.md
CHANGED
@@ -1,19 +1,98 @@
|
|
1
|
-
#
|
1
|
+
# TypeScript
|
2
2
|
|
3
|
+
## Installation
|
3
4
|
|
4
|
-
|
5
|
+
1. Run the TypeScript installer
|
5
6
|
|
6
|
-
|
7
|
+
```bash
|
8
|
+
bundle exec rails webpacker:install:typescript
|
9
|
+
```
|
10
|
+
|
11
|
+
After that, a new file called `hello_typescript.ts` will be present in your `packs` directory (or rather the `source_entry_path` of your `webpacker.yml` configuration). You're now ready to write TypeScript.
|
12
|
+
|
13
|
+
## (Optional) Adding Compile-Time Type Checking
|
14
|
+
|
15
|
+
The default installation only transpiles your TypeScript code using Babel. If you would like to enable type checking as part of the Webpack compilation process (i.e. fail the build if there are TS errors), you can do the following:
|
16
|
+
|
17
|
+
1. Install the Fork TS Checker Webpack Plugin
|
18
|
+
|
19
|
+
```sh
|
20
|
+
yarn add --dev fork-ts-checker-webpack-plugin
|
21
|
+
```
|
22
|
+
|
23
|
+
2. Then add it to your development environment config in `config/webpack/development.js`
|
24
|
+
|
25
|
+
```js
|
26
|
+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
27
|
+
const path = require("path");
|
28
|
+
|
29
|
+
environment.plugins.append(
|
30
|
+
"ForkTsCheckerWebpackPlugin",
|
31
|
+
new ForkTsCheckerWebpackPlugin({
|
32
|
+
typescript: {
|
33
|
+
configFile: path.resolve(__dirname, "../../tsconfig.json"),
|
34
|
+
},
|
35
|
+
async: false,
|
36
|
+
})
|
37
|
+
);
|
38
|
+
```
|
39
|
+
|
40
|
+
If you are `fork-ts-checker-webpack-plugin` older than 5.0, the `tsconfig` option also needs to be specified:
|
41
|
+
|
42
|
+
```js
|
43
|
+
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
|
44
|
+
const path = require("path");
|
45
|
+
|
46
|
+
environment.plugins.append(
|
47
|
+
"ForkTsCheckerWebpackPlugin",
|
48
|
+
new ForkTsCheckerWebpackPlugin({
|
49
|
+
// this is a relative path to your project's TypeScript config
|
50
|
+
tsconfig: path.resolve(__dirname, "../../tsconfig.json"),
|
51
|
+
// non-async so type checking will block compilation
|
52
|
+
async: false,
|
53
|
+
})
|
54
|
+
);
|
55
|
+
```
|
56
|
+
|
57
|
+
## Upgrading to 5.1
|
58
|
+
|
59
|
+
If you update your App to `webpacker >= 5.1` and had TypeScript installed before, you need to add some new/remove some old configurations:
|
60
|
+
|
61
|
+
1. Remove old packages:
|
62
|
+
- `yarn remove ts-loader`
|
63
|
+
|
64
|
+
2. Add new packages:
|
65
|
+
- `yarn add @babel/preset-typescript`
|
66
|
+
|
67
|
+
3. Remove old configuration files:
|
68
|
+
- Delete this file: `config/webpack/loaders/typescript.js`
|
69
|
+
|
70
|
+
4. Remove the following lines from `config/webpack/environment.js`:
|
71
|
+
- `const typescript = require('./loaders/typescript')`
|
72
|
+
- `environment.loaders.prepend('typescript', typescript)`
|
73
|
+
|
74
|
+
5. Add the TypeScript preset to your `babel.config.js`:
|
75
|
+
- This line `['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]` has to be added as the last item to the `presets` array in your `babel.config.js`
|
76
|
+
|
77
|
+
### Upgrading to 5.1 for Vue users
|
78
|
+
|
79
|
+
1. Remove old packages:
|
80
|
+
- `yarn remove ts-loader pnp-webpack-plugin`
|
81
|
+
|
82
|
+
2. Follow point 3 and 4 from the `TypeScript with Vue components` section
|
83
|
+
|
84
|
+
## TypeScript with React
|
85
|
+
|
86
|
+
1. Setup react using Webpacker [react installer](../README.md#react). Then run the TypeScript installer
|
7
87
|
|
8
88
|
```bash
|
9
89
|
bundle exec rails webpacker:install:typescript
|
10
|
-
yarn add @types/react @types/react-dom
|
11
90
|
```
|
12
91
|
|
13
|
-
2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid
|
14
|
-
now you can use
|
92
|
+
2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid TypeScript and
|
93
|
+
now you can use TypeScript, JSX with React.
|
15
94
|
|
16
|
-
##
|
95
|
+
## TypeScript with Vue components
|
17
96
|
|
18
97
|
1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
|
19
98
|
|
@@ -22,37 +101,22 @@ bundle exec rails webpacker:install:typescript
|
|
22
101
|
```
|
23
102
|
|
24
103
|
2. Rename generated `hello_vue.js` to `hello_vue.ts`.
|
25
|
-
3.
|
26
|
-
4. Change the generated `config
|
104
|
+
3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
|
105
|
+
4. Change the generated `babel.config.js` from
|
27
106
|
|
28
107
|
```js
|
29
|
-
|
30
|
-
test: /\.(ts|tsx)?(\.erb)?$/,
|
31
|
-
use: [{
|
32
|
-
loader: 'ts-loader'
|
33
|
-
}]
|
34
|
-
}
|
108
|
+
["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
|
35
109
|
```
|
36
110
|
|
37
111
|
to
|
38
112
|
|
39
113
|
```js
|
40
|
-
|
41
|
-
|
42
|
-
module.exports = {
|
43
|
-
test: /\.(ts|tsx)?(\.erb)?$/,
|
44
|
-
use: [{
|
45
|
-
loader: 'ts-loader',
|
46
|
-
options: PnpWebpackPlugin.tsLoaderOptions({
|
47
|
-
appendTsSuffixTo: [/\.vue$/]
|
48
|
-
})
|
49
|
-
}]
|
50
|
-
}
|
114
|
+
["babel-preset-typescript-vue", { "allExtensions": true, "isTSX": true }]
|
51
115
|
```
|
52
116
|
|
53
|
-
and now you can use `<script lang="ts">` in your `.vue` component files. See [the
|
117
|
+
and now you can use `<script lang="ts">` in your `.vue` component files. See [the babel-preset-typescript-vue docs](https://www.npmjs.com/package/babel-preset-typescript-vue) for more info.
|
54
118
|
|
55
|
-
## HTML templates with
|
119
|
+
## HTML templates with TypeScript and Angular
|
56
120
|
|
57
121
|
After you have installed Angular using `bundle exec rails webpacker:install:angular`
|
58
122
|
you would need to follow these steps to add HTML templates support:
|
data/docs/webpack-dev-server.md
CHANGED
@@ -19,7 +19,7 @@ Now if you refresh your Rails view everything should work as expected.
|
|
19
19
|
Webpacker out-of-the-box supports HMR with `webpack-dev-server` and
|
20
20
|
you can toggle it by setting `dev_server/hmr` option inside `webpacker.yml`.
|
21
21
|
|
22
|
-
|
22
|
+
Check out this guide for more information:
|
23
23
|
|
24
24
|
- https://webpack.js.org/configuration/dev-server/#devserver-hot
|
25
25
|
|
data/jetpacker.gemspec
CHANGED
@@ -6,12 +6,12 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.version = Jetpacker::VERSION
|
7
7
|
s.authors = [ "Tung Nguyen" ]
|
8
8
|
s.email = [ "tongueroo@gmail.com" ]
|
9
|
-
# Only commented out, so people do not accidentally contact incorrect person for jetspacker specific related issues.
|
9
|
+
# Only commented out, so people do not accidentally contact the incorrect person for jetspacker specific related issues.
|
10
10
|
# Credit goes to original authors of the work:
|
11
11
|
# s.authors = [ "David Heinemeier Hansson", "Gaurav Tiwari" ]
|
12
12
|
# s.email = [ "david@basecamp.com", "gaurav@gauravtiwari.co.uk" ]
|
13
13
|
s.summary = "Use webpack to manage app-like JavaScript modules in Jets"
|
14
|
-
s.homepage = "https://github.com/
|
14
|
+
s.homepage = "https://github.com/tongueroo/jetpacker"
|
15
15
|
s.license = "MIT"
|
16
16
|
|
17
17
|
s.metadata = {
|
@@ -19,11 +19,12 @@ Gem::Specification.new do |s|
|
|
19
19
|
"changelog_uri" => "https://github.com/tongueroo/jetpacker/blob/v#{Jetpacker::VERSION}/CHANGELOG.md"
|
20
20
|
}
|
21
21
|
|
22
|
-
s.required_ruby_version = ">= 2.
|
22
|
+
s.required_ruby_version = ">= 2.4.0"
|
23
23
|
|
24
|
-
s.add_dependency "activesupport", ">=
|
25
|
-
s.add_dependency "railties", ">=
|
24
|
+
s.add_dependency "activesupport", ">= 5.2"
|
25
|
+
s.add_dependency "railties", ">= 5.2"
|
26
26
|
s.add_dependency "rack-proxy", ">= 0.6.1"
|
27
|
+
s.add_dependency "semantic_range", ">= 2.3.0"
|
27
28
|
|
28
29
|
s.add_development_dependency "bundler", ">= 1.3.0"
|
29
30
|
s.add_development_dependency "rubocop", "< 0.69"
|
@@ -6,18 +6,26 @@ default: &default
|
|
6
6
|
public_root_path: public
|
7
7
|
public_output_path: packs
|
8
8
|
cache_path: tmp/cache/webpacker
|
9
|
-
check_yarn_integrity: false
|
10
9
|
webpack_compile_output: true
|
11
10
|
|
12
11
|
# Additional paths webpack should lookup modules
|
13
12
|
# ['app/assets', 'engine/foo/app/assets']
|
14
|
-
resolved_paths: []
|
13
|
+
# Note: Different from original webpacker default which is resolved_paths: []
|
14
|
+
# Unsure if app/assets is better default. Seems convenient.
|
15
|
+
resolved_paths: ['app/assets']
|
16
|
+
additional_paths: []
|
15
17
|
|
16
18
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
17
19
|
cache_manifest: false
|
18
20
|
|
19
21
|
# Extract and emit a css file
|
20
|
-
extract_css: false
|
22
|
+
# Note: Different from original webpacker default which is extract_css: false
|
23
|
+
# Unsure if this is really a better default. But want to maintain backward compatiblity when folks upgrade Jets.
|
24
|
+
# Notes:
|
25
|
+
# https://github.com/rails/webpacker/issues/2059
|
26
|
+
# https://github.com/rails/webpacker/issues/2202
|
27
|
+
# https://github.com/rails/webpacker/issues/2342
|
28
|
+
extract_css: true
|
21
29
|
|
22
30
|
static_assets_extensions:
|
23
31
|
- .jpg
|
@@ -52,9 +60,6 @@ development:
|
|
52
60
|
<<: *default
|
53
61
|
compile: true
|
54
62
|
|
55
|
-
# Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
|
56
|
-
check_yarn_integrity: true
|
57
|
-
|
58
63
|
# Reference: https://webpack.js.org/configuration/dev-server/
|
59
64
|
dev_server:
|
60
65
|
https: false
|
data/lib/install/template.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Install Webpacker
|
2
2
|
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
3
3
|
|
4
|
-
|
4
|
+
say "Copying webpack core config"
|
5
5
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
6
6
|
|
7
7
|
say "Copying postcss.config.js to app root directory"
|
@@ -13,12 +13,12 @@ copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
|
|
13
13
|
say "Copying .browserslistrc to app root directory"
|
14
14
|
copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
|
15
15
|
|
16
|
-
if Dir.exists?(Webpacker.config.source_path)
|
17
|
-
|
18
|
-
else
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
# if Dir.exists?(Webpacker.config.source_path)
|
17
|
+
# say "The JavaScript app source directory already exists"
|
18
|
+
# else
|
19
|
+
# say "Creating JavaScript app source directory"
|
20
|
+
# directory "#{__dir__}/javascript", Webpacker.config.source_path
|
21
|
+
# end
|
22
22
|
|
23
23
|
apply "#{__dir__}/binstubs.rb"
|
24
24
|
|
data/lib/install/typescript.rb
CHANGED
@@ -26,6 +26,10 @@ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
|
|
26
26
|
insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
|
27
27
|
"environment.loaders.prepend('typescript', typescript)\n",
|
28
28
|
before: "module.exports"
|
29
|
+
say "Adding TypeScript preset to babel.config.js"
|
30
|
+
insert_into_file Jets.root.join("babel.config.js").to_s,
|
31
|
+
",\n ['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]",
|
32
|
+
before: /\s*\].filter\(Boolean\),\n\s*plugins: \[/
|
29
33
|
|
30
34
|
say "Copying tsconfig.json to the Rails root directory for typescript"
|
31
35
|
copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"
|
@@ -41,6 +45,6 @@ copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
|
|
41
45
|
"#{Webpacker.config.source_entry_path}/hello_typescript.ts"
|
42
46
|
|
43
47
|
say "Installing all typescript dependencies"
|
44
|
-
run "yarn add typescript
|
48
|
+
run "yarn add typescript @babel/preset-typescript #{additional_packages}"
|
45
49
|
|
46
50
|
say "Webpacker now supports typescript 🎉", :green
|
data/lib/jetpacker.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "webpacker"
|
data/lib/jetpacker/version.rb
CHANGED
@@ -1,24 +1,31 @@
|
|
1
|
+
require "semantic_range"
|
1
2
|
namespace :webpacker do
|
2
3
|
desc "Verifies if Node.js is installed"
|
3
4
|
task :check_node do
|
4
5
|
begin
|
5
|
-
node_version = `node -v || nodejs -v
|
6
|
+
node_version = `node -v || nodejs -v`.strip
|
6
7
|
raise Errno::ENOENT if node_version.blank?
|
7
8
|
|
8
9
|
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
9
|
-
|
10
|
+
node_range = JSON.parse(pkg_path.read)["engines"]["node"]
|
11
|
+
is_valid = SemanticRange.satisfies?(node_version, node_range) rescue false
|
12
|
+
semver_major = node_version[/\d+/] rescue nil
|
13
|
+
is_unstable = semver_major.to_i.odd? rescue false
|
10
14
|
|
11
|
-
|
12
|
-
|
15
|
+
if is_unstable
|
16
|
+
$stderr.puts "Warning: you are using an unstable release of Node.js (#{node_version}). If you encounter issues with Node.js, consider switching to an Active LTS release. More info: https://docs.npmjs.com/try-the-latest-stable-version-of-node"
|
17
|
+
end
|
13
18
|
|
14
|
-
unless
|
15
|
-
$stderr.puts "Webpacker requires Node.js #{
|
19
|
+
unless is_valid
|
20
|
+
$stderr.puts "Webpacker requires Node.js \"#{node_range}\" and you are using #{node_version}"
|
16
21
|
$stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/"
|
17
|
-
$stderr.puts "Exiting!"
|
22
|
+
$stderr.puts "Exiting!"
|
23
|
+
exit!
|
18
24
|
end
|
19
25
|
rescue Errno::ENOENT
|
20
26
|
$stderr.puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
|
21
|
-
$stderr.puts "Exiting!"
|
27
|
+
$stderr.puts "Exiting!"
|
28
|
+
exit!
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -1,24 +1,31 @@
|
|
1
|
+
require "semantic_range"
|
1
2
|
namespace :webpacker do
|
2
3
|
desc "Verifies if Yarn is installed"
|
3
4
|
task :check_yarn do
|
4
5
|
begin
|
5
|
-
yarn_version = `yarn --version
|
6
|
+
yarn_version = `yarn --version`.strip
|
6
7
|
raise Errno::ENOENT if yarn_version.blank?
|
7
8
|
|
8
9
|
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
9
|
-
|
10
|
+
yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
|
11
|
+
is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
|
12
|
+
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=2.0.0") rescue false
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
unless is_valid
|
15
|
+
$stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
|
16
|
+
if is_unsupported
|
17
|
+
$stderr.puts "This version of Webpacker does not support Yarn #{yarn_version}. Please downgrade to a supported version of Yarn https://yarnpkg.com/lang/en/docs/install/"
|
18
|
+
$stderr.puts "For information on using Webpacker with Yarn 2.0, see https://github.com/rails/webpacker/issues/2112"
|
19
|
+
else
|
20
|
+
$stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
|
21
|
+
end
|
22
|
+
$stderr.puts "Exiting!"
|
23
|
+
exit!
|
18
24
|
end
|
19
25
|
rescue Errno::ENOENT
|
20
26
|
$stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/"
|
21
|
-
$stderr.puts "Exiting!"
|
27
|
+
$stderr.puts "Exiting!"
|
28
|
+
exit!
|
22
29
|
end
|
23
30
|
end
|
24
31
|
end
|
@@ -4,18 +4,22 @@ require "webpacker/configuration"
|
|
4
4
|
|
5
5
|
namespace :webpacker do
|
6
6
|
desc "Remove old compiled webpacks"
|
7
|
-
task :clean, [:keep] => ["webpacker:verify_install", :environment] do |_, args|
|
7
|
+
task :clean, [:keep, :age] => ["webpacker:verify_install", :environment] do |_, args|
|
8
8
|
Webpacker.ensure_log_goes_to_stdout do
|
9
|
-
Webpacker.clean(Integer(args.keep || 2))
|
9
|
+
Webpacker.clean(Integer(args.keep || 2), Integer(args.age || 3600))
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
skip_webpacker_clean = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
|
15
|
+
|
16
|
+
unless skip_webpacker_clean
|
17
|
+
# Run clean if the assets:clean is run
|
18
|
+
if Rake::Task.task_defined?("assets:clean")
|
19
|
+
Rake::Task["assets:clean"].enhance do
|
20
|
+
Rake::Task["webpacker:clean"].invoke
|
21
|
+
end
|
22
|
+
else
|
23
|
+
Rake::Task.define_task("assets:clean" => "webpacker:clean")
|
18
24
|
end
|
19
|
-
else
|
20
|
-
Rake::Task.define_task("assets:clean" => "webpacker:clean")
|
21
25
|
end
|