webpacker 4.0.7 → 5.4.4
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 +46 -0
- data/.node-version +1 -1
- data/.rubocop.yml +118 -14
- data/CHANGELOG.md +301 -138
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +123 -92
- data/README.md +86 -211
- data/docs/css.md +72 -6
- data/docs/deployment.md +40 -11
- data/docs/docker.md +33 -14
- data/docs/engines.md +53 -3
- data/docs/env.md +0 -2
- data/docs/es6.md +19 -1
- data/docs/integrations.md +220 -0
- data/docs/target.md +22 -0
- data/docs/testing.md +2 -3
- data/docs/troubleshooting.md +39 -9
- data/docs/typescript.md +93 -26
- data/docs/webpack-dev-server.md +2 -2
- data/docs/webpack.md +18 -3
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/{Gemfile-rails.4.2.x → Gemfile-rails.6.0.x} +1 -1
- data/lib/install/bin/webpack +0 -1
- data/lib/install/bin/webpack-dev-server +0 -1
- data/lib/install/coffee.rb +1 -1
- data/lib/install/config/babel.config.js +23 -13
- data/lib/install/config/webpacker.yml +3 -6
- data/lib/install/elm.rb +1 -1
- data/lib/install/erb.rb +2 -2
- data/lib/install/examples/angular/hello_angular/polyfills.ts +2 -2
- data/lib/install/examples/react/babel.config.js +28 -14
- data/lib/install/examples/react/tsconfig.json +2 -1
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/examples/typescript/tsconfig.json +2 -1
- data/lib/install/loaders/elm.js +9 -6
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +14 -6
- data/lib/install/typescript.rb +6 -13
- data/lib/install/vue.rb +1 -1
- data/lib/tasks/installers.rake +1 -0
- data/lib/tasks/webpacker/check_node.rake +15 -8
- data/lib/tasks/webpacker/check_yarn.rake +16 -10
- data/lib/tasks/webpacker/clean.rake +25 -0
- data/lib/tasks/webpacker/clobber.rake +8 -4
- data/lib/tasks/webpacker/compile.rake +2 -10
- data/lib/tasks/webpacker/yarn_install.rake +11 -1
- data/lib/tasks/webpacker.rake +2 -0
- data/lib/webpacker/commands.rb +53 -1
- data/lib/webpacker/compiler.rb +21 -10
- data/lib/webpacker/configuration.rb +36 -13
- data/lib/webpacker/dev_server.rb +1 -1
- data/lib/webpacker/dev_server_proxy.rb +5 -9
- data/lib/webpacker/dev_server_runner.rb +6 -6
- data/lib/webpacker/env.rb +6 -2
- data/lib/webpacker/helper.rb +70 -25
- data/lib/webpacker/manifest.rb +4 -4
- data/lib/webpacker/railtie.rb +6 -43
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +2 -2
- data/lib/webpacker.rb +9 -1
- data/package/__tests__/config.js +12 -24
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +14 -1
- data/package/config.js +6 -11
- data/package/configPath.js +3 -0
- data/package/config_types/config_list.js +3 -3
- data/package/config_types/config_object.js +1 -1
- 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 +18 -8
- data/package/environments/development.js +39 -37
- data/package/environments/production.js +12 -2
- data/package/rules/babel.js +12 -5
- data/package/rules/file.js +3 -2
- data/package/rules/node_modules.js +3 -5
- data/package/rules/sass.js +11 -2
- data/package/utils/__tests__/get_style_rule.js +9 -0
- data/package/utils/deep_merge.js +5 -5
- data/package/utils/get_style_rule.js +7 -12
- data/package/utils/helpers.js +10 -10
- data/package.json +43 -43
- data/test/command_test.rb +6 -0
- data/test/compiler_test.rb +10 -6
- data/test/configuration_test.rb +40 -30
- data/test/dev_server_runner_test.rb +1 -1
- data/test/dev_server_test.rb +22 -0
- data/test/helper_test.rb +58 -9
- data/test/manifest_test.rb +37 -6
- data/test/rake_tasks_test.rb +17 -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/bin/webpack +0 -1
- data/test/test_app/bin/webpack-dev-server +0 -1
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/webpacker.yml +8 -1
- data/test/test_app/public/packs/manifest.json +4 -0
- data/test/webpack_runner_test.rb +1 -1
- data/webpacker.gemspec +6 -4
- data/yarn.lock +4350 -4099
- metadata +63 -23
- data/.travis.yml +0 -53
- data/gemfiles/Gemfile-rails.5.0.x +0 -9
- data/gemfiles/Gemfile-rails.5.1.x +0 -9
- data/lib/install/loaders/typescript.js +0 -11
data/docs/typescript.md
CHANGED
@@ -1,55 +1,122 @@
|
|
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
|
-
1. Setup
|
97
|
+
1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
|
19
98
|
|
20
99
|
```bash
|
21
100
|
bundle exec rails webpacker:install:typescript
|
22
101
|
```
|
23
102
|
|
24
103
|
2. Rename generated `hello_vue.js` to `hello_vue.ts`.
|
25
|
-
3.
|
104
|
+
3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
|
105
|
+
4. Change the generated `babel.config.js` from
|
26
106
|
|
27
107
|
```js
|
28
|
-
|
29
|
-
test: /\.(ts|tsx)?(\.erb)?$/,
|
30
|
-
use: [{
|
31
|
-
loader: 'ts-loader'
|
32
|
-
}]
|
33
|
-
}
|
108
|
+
["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
|
34
109
|
```
|
35
110
|
|
36
111
|
to
|
37
112
|
|
38
113
|
```js
|
39
|
-
|
40
|
-
test: /\.(ts|tsx)?(\.erb)?$/,
|
41
|
-
use: [{
|
42
|
-
loader: 'ts-loader',
|
43
|
-
options: {
|
44
|
-
appendTsSuffixTo: [/\.vue$/]
|
45
|
-
}
|
46
|
-
}]
|
47
|
-
}
|
114
|
+
["babel-preset-typescript-vue", { "allExtensions": true, "isTSX": true }]
|
48
115
|
```
|
49
116
|
|
50
|
-
and now you can use `<script lang="ts">` in your `.vue` component files.
|
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.
|
51
118
|
|
52
|
-
## HTML templates with
|
119
|
+
## HTML templates with TypeScript and Angular
|
53
120
|
|
54
121
|
After you have installed Angular using `bundle exec rails webpacker:install:angular`
|
55
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
|
|
@@ -38,7 +38,7 @@ If you use Nginx in development to proxy requests to your Rails server from
|
|
38
38
|
another domain, like `myapp.dev`, the Webpacker middleware will be able to
|
39
39
|
forward requests for "packs" to the webpack dev server.
|
40
40
|
|
41
|
-
If you're using `inline` mode
|
41
|
+
If you're using `inline` mode behind Nginx, you may also need to provide the
|
42
42
|
hostname to webpack dev server so it can initiate the websocket connection for
|
43
43
|
live reloading ([Webpack
|
44
44
|
docs](https://webpack.js.org/configuration/dev-server/#devserver-public)).
|
data/docs/webpack.md
CHANGED
@@ -189,9 +189,10 @@ const { environment } = require('@rails/webpacker')
|
|
189
189
|
const merge = require('webpack-merge')
|
190
190
|
|
191
191
|
const myCssLoaderOptions = {
|
192
|
-
modules:
|
192
|
+
modules: {
|
193
|
+
localIdentName: '[name]__[local]___[hash:base64:5]'
|
194
|
+
},
|
193
195
|
sourceMap: true,
|
194
|
-
localIdentName: '[name]__[local]___[hash:base64:5]'
|
195
196
|
}
|
196
197
|
|
197
198
|
const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
|
@@ -277,7 +278,7 @@ environment.splitChunks()
|
|
277
278
|
environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
|
278
279
|
```
|
279
280
|
|
280
|
-
Then use
|
281
|
+
Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
|
281
282
|
packs with the chunks in your view, which creates html tags for all the chunks.
|
282
283
|
|
283
284
|
```erb
|
@@ -304,6 +305,20 @@ get duplicated chunks on the page.
|
|
304
305
|
|
305
306
|
For the old configuration with the CommonsChunkPlugin see below. **Note** that this functionality is deprecated in Webpack V4.
|
306
307
|
|
308
|
+
#### Preloading
|
309
|
+
|
310
|
+
Before preload or prefetch your assets, please read [https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content](https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content).
|
311
|
+
|
312
|
+
Webpack also provide it's own methods for preload or prefetch [https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c](https://medium.com/webpack/link-rel-prefetch-preload-in-webpack-51a52358f84c).
|
313
|
+
|
314
|
+
You can preload your assets with the `preload_pack_asset` helper if you have Rails >= 5.2.x.
|
315
|
+
|
316
|
+
```erb
|
317
|
+
<%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
|
318
|
+
```
|
319
|
+
|
320
|
+
**Warning:** You don't want to preload the css, you want to preload the fonts and images inside the css so that fonts, css, and images can all be downloaded in parallel instead of waiting for the browser to parse the css.
|
321
|
+
|
307
322
|
### Add common chunks (deprecated in Webpack V4)
|
308
323
|
|
309
324
|
The CommonsChunkPlugin is an opt-in feature that creates a separate file (known as a chunk), consisting of common modules shared between multiple entry points. By separating common modules from bundles, the resulting chunked file can be loaded once initially, and stored in the cache for later use. This results in page speed optimizations as the browser can quickly serve the shared code from the cache, rather than being forced to load a larger bundle whenever a new page is visited.
|
data/gemfiles/Gemfile-rails-edge
CHANGED
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
4
4
|
|
5
5
|
gemspec path: "../"
|
6
6
|
|
7
|
-
gem "rails", github: "rails/rails"
|
7
|
+
gem "rails", github: "rails/rails", branch: "main"
|
8
8
|
gem "arel", github: "rails/arel"
|
9
9
|
gem "rake", ">= 11.1"
|
10
10
|
gem "rack-proxy", require: false
|
data/lib/install/bin/webpack
CHANGED
data/lib/install/coffee.rb
CHANGED
@@ -6,7 +6,7 @@ copy_file "#{__dir__}/loaders/coffee.js", Rails.root.join("config/webpack/loader
|
|
6
6
|
say "Adding coffee loader to config/webpack/environment.js"
|
7
7
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
8
8
|
"const coffee = require('./loaders/coffee')\n",
|
9
|
-
after:
|
9
|
+
after: /require\(('|")@rails\/webpacker\1\);?\n/
|
10
10
|
|
11
11
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
12
12
|
"environment.loaders.prepend('coffee', coffee)\n",
|
@@ -18,7 +18,7 @@ module.exports = function(api) {
|
|
18
18
|
return {
|
19
19
|
presets: [
|
20
20
|
isTestEnv && [
|
21
|
-
|
21
|
+
'@babel/preset-env',
|
22
22
|
{
|
23
23
|
targets: {
|
24
24
|
node: 'current'
|
@@ -26,7 +26,7 @@ module.exports = function(api) {
|
|
26
26
|
}
|
27
27
|
],
|
28
28
|
(isProductionEnv || isDevelopmentEnv) && [
|
29
|
-
|
29
|
+
'@babel/preset-env',
|
30
30
|
{
|
31
31
|
forceAllTransforms: true,
|
32
32
|
useBuiltIns: 'entry',
|
@@ -37,32 +37,42 @@ module.exports = function(api) {
|
|
37
37
|
]
|
38
38
|
].filter(Boolean),
|
39
39
|
plugins: [
|
40
|
-
|
41
|
-
|
42
|
-
isTestEnv &&
|
43
|
-
|
40
|
+
'babel-plugin-macros',
|
41
|
+
'@babel/plugin-syntax-dynamic-import',
|
42
|
+
isTestEnv && 'babel-plugin-dynamic-import-node',
|
43
|
+
'@babel/plugin-transform-destructuring',
|
44
44
|
[
|
45
|
-
|
45
|
+
'@babel/plugin-proposal-class-properties',
|
46
46
|
{
|
47
47
|
loose: true
|
48
48
|
}
|
49
49
|
],
|
50
50
|
[
|
51
|
-
|
51
|
+
'@babel/plugin-proposal-object-rest-spread',
|
52
52
|
{
|
53
53
|
useBuiltIns: true
|
54
54
|
}
|
55
55
|
],
|
56
56
|
[
|
57
|
-
|
57
|
+
'@babel/plugin-proposal-private-methods',
|
58
58
|
{
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
loose: true
|
60
|
+
}
|
61
|
+
],
|
62
|
+
[
|
63
|
+
'@babel/plugin-proposal-private-property-in-object',
|
64
|
+
{
|
65
|
+
loose: true
|
66
|
+
}
|
67
|
+
],
|
68
|
+
[
|
69
|
+
'@babel/plugin-transform-runtime',
|
70
|
+
{
|
71
|
+
helpers: false
|
62
72
|
}
|
63
73
|
],
|
64
74
|
[
|
65
|
-
|
75
|
+
'@babel/plugin-transform-regenerator',
|
66
76
|
{
|
67
77
|
async: false
|
68
78
|
}
|
@@ -6,12 +6,11 @@ default: &default
|
|
6
6
|
public_root_path: public
|
7
7
|
public_output_path: packs
|
8
8
|
cache_path: tmp/cache/webpacker
|
9
|
-
|
10
|
-
webpack_compile_output: false
|
9
|
+
webpack_compile_output: true
|
11
10
|
|
12
11
|
# Additional paths webpack should lookup modules
|
13
12
|
# ['app/assets', 'engine/foo/app/assets']
|
14
|
-
|
13
|
+
additional_paths: []
|
15
14
|
|
16
15
|
# Reload manifest.json on all requests so we reload latest compiled packs
|
17
16
|
cache_manifest: false
|
@@ -52,9 +51,6 @@ development:
|
|
52
51
|
<<: *default
|
53
52
|
compile: true
|
54
53
|
|
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
54
|
# Reference: https://webpack.js.org/configuration/dev-server/
|
59
55
|
dev_server:
|
60
56
|
https: false
|
@@ -69,6 +65,7 @@ development:
|
|
69
65
|
disable_host_check: true
|
70
66
|
use_local_ip: false
|
71
67
|
quiet: false
|
68
|
+
pretty: false
|
72
69
|
headers:
|
73
70
|
'Access-Control-Allow-Origin': '*'
|
74
71
|
watch_options:
|
data/lib/install/elm.rb
CHANGED
@@ -6,7 +6,7 @@ copy_file "#{__dir__}/loaders/elm.js", Rails.root.join("config/webpack/loaders/e
|
|
6
6
|
say "Adding elm loader to config/webpack/environment.js"
|
7
7
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
8
8
|
"const elm = require('./loaders/elm')\n",
|
9
|
-
after:
|
9
|
+
after: /require\(('|")@rails\/webpacker\1\);?\n/
|
10
10
|
|
11
11
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
12
12
|
"environment.loaders.prepend('elm', elm)\n",
|
data/lib/install/erb.rb
CHANGED
@@ -5,8 +5,8 @@ copy_file "#{__dir__}/loaders/erb.js", Rails.root.join("config/webpack/loaders/e
|
|
5
5
|
|
6
6
|
say "Adding erb loader to config/webpack/environment.js"
|
7
7
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
8
|
-
"const erb =
|
9
|
-
after:
|
8
|
+
"const erb = require('./loaders/erb')\n",
|
9
|
+
after: /require\(('|")@rails\/webpacker\1\);?\n/
|
10
10
|
|
11
11
|
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
12
12
|
"environment.loaders.prepend('erb', erb)\n",
|
@@ -38,8 +38,8 @@
|
|
38
38
|
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
39
39
|
|
40
40
|
/** Evergreen browsers require these. **/
|
41
|
-
import 'core-js/
|
42
|
-
import 'core-js/
|
41
|
+
import 'core-js/es/reflect';
|
42
|
+
import 'core-js/proposals/reflect-metadata';
|
43
43
|
|
44
44
|
|
45
45
|
/**
|
@@ -18,15 +18,17 @@ module.exports = function(api) {
|
|
18
18
|
return {
|
19
19
|
presets: [
|
20
20
|
isTestEnv && [
|
21
|
-
|
21
|
+
'@babel/preset-env',
|
22
22
|
{
|
23
23
|
targets: {
|
24
24
|
node: 'current'
|
25
|
-
}
|
26
|
-
|
25
|
+
},
|
26
|
+
modules: 'commonjs'
|
27
|
+
},
|
28
|
+
'@babel/preset-react'
|
27
29
|
],
|
28
30
|
(isProductionEnv || isDevelopmentEnv) && [
|
29
|
-
|
31
|
+
'@babel/preset-env',
|
30
32
|
{
|
31
33
|
forceAllTransforms: true,
|
32
34
|
useBuiltIns: 'entry',
|
@@ -36,7 +38,7 @@ module.exports = function(api) {
|
|
36
38
|
}
|
37
39
|
],
|
38
40
|
[
|
39
|
-
|
41
|
+
'@babel/preset-react',
|
40
42
|
{
|
41
43
|
development: isDevelopmentEnv || isTestEnv,
|
42
44
|
useBuiltIns: true
|
@@ -44,24 +46,36 @@ module.exports = function(api) {
|
|
44
46
|
]
|
45
47
|
].filter(Boolean),
|
46
48
|
plugins: [
|
47
|
-
|
48
|
-
|
49
|
-
isTestEnv &&
|
50
|
-
|
49
|
+
'babel-plugin-macros',
|
50
|
+
'@babel/plugin-syntax-dynamic-import',
|
51
|
+
isTestEnv && 'babel-plugin-dynamic-import-node',
|
52
|
+
'@babel/plugin-transform-destructuring',
|
51
53
|
[
|
52
|
-
|
54
|
+
'@babel/plugin-proposal-class-properties',
|
53
55
|
{
|
54
56
|
loose: true
|
55
57
|
}
|
56
58
|
],
|
57
59
|
[
|
58
|
-
|
60
|
+
'@babel/plugin-proposal-object-rest-spread',
|
59
61
|
{
|
60
62
|
useBuiltIns: true
|
61
63
|
}
|
62
64
|
],
|
63
65
|
[
|
64
|
-
|
66
|
+
'@babel/plugin-proposal-private-methods',
|
67
|
+
{
|
68
|
+
loose: true
|
69
|
+
}
|
70
|
+
],
|
71
|
+
[
|
72
|
+
'@babel/plugin-proposal-private-property-in-object',
|
73
|
+
{
|
74
|
+
loose: true
|
75
|
+
}
|
76
|
+
],
|
77
|
+
[
|
78
|
+
'@babel/plugin-transform-runtime',
|
65
79
|
{
|
66
80
|
helpers: false,
|
67
81
|
regenerator: true,
|
@@ -69,13 +83,13 @@ module.exports = function(api) {
|
|
69
83
|
}
|
70
84
|
],
|
71
85
|
[
|
72
|
-
|
86
|
+
'@babel/plugin-transform-regenerator',
|
73
87
|
{
|
74
88
|
async: false
|
75
89
|
}
|
76
90
|
],
|
77
91
|
isProductionEnv && [
|
78
|
-
|
92
|
+
'babel-plugin-transform-react-remove-prop-types',
|
79
93
|
{
|
80
94
|
removeImport: true
|
81
95
|
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/* eslint no-console: 0 */
|
2
|
+
// Run this example by adding <%= javascript_pack_tag 'hello_svelte' %> (and
|
3
|
+
// <%= stylesheet_pack_tag 'hello_svelte' %> if you have styles in your component)
|
4
|
+
// to the head of your layout file,
|
5
|
+
// like app/views/layouts/application.html.erb.
|
6
|
+
// All it does is render <div>Hello Svelte!</div> at the bottom of the page.
|
7
|
+
|
8
|
+
import App from '../app.svelte'
|
9
|
+
|
10
|
+
document.addEventListener('DOMContentLoaded', () => {
|
11
|
+
const app = new App({
|
12
|
+
target: document.body,
|
13
|
+
props: {
|
14
|
+
name: 'Svelte'
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
18
|
+
window.app = app;
|
19
|
+
})
|
20
|
+
|
data/lib/install/loaders/elm.js
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
const { resolve } = require('path')
|
2
2
|
|
3
3
|
const isProduction = process.env.NODE_ENV === 'production'
|
4
|
+
const isDevelopment = process.env.NODE_ENV === 'development'
|
4
5
|
const elmSource = resolve(process.cwd())
|
5
6
|
const elmBinary = `${elmSource}/node_modules/.bin/elm`
|
6
7
|
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
const options = {
|
9
|
+
cwd: elmSource,
|
10
|
+
pathToElm: elmBinary,
|
11
|
+
optimize: isProduction,
|
12
|
+
verbose: isDevelopment,
|
13
|
+
debug: isDevelopment
|
14
|
+
}
|
12
15
|
|
13
16
|
const elmWebpackLoader = {
|
14
17
|
loader: 'elm-webpack-loader',
|
15
|
-
options:
|
18
|
+
options: options
|
16
19
|
}
|
17
20
|
|
18
21
|
module.exports = {
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
say "Copying svelte loader to config/webpack/loaders"
|
4
|
+
copy_file "#{__dir__}/loaders/svelte.js", Rails.root.join("config/webpack/loaders/svelte.js").to_s
|
5
|
+
|
6
|
+
say "Adding svelte loader to config/webpack/environment.js"
|
7
|
+
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
8
|
+
"const svelte = require('./loaders/svelte')\n",
|
9
|
+
after: /require\(('|")@rails\/webpacker\1\);?\n/
|
10
|
+
|
11
|
+
insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
|
12
|
+
"environment.loaders.prepend('svelte', svelte)\n",
|
13
|
+
before: "module.exports"
|
14
|
+
|
15
|
+
say "Copying Svelte example entry file to #{Webpacker.config.source_entry_path}"
|
16
|
+
copy_file "#{__dir__}/examples/svelte/hello_svelte.js",
|
17
|
+
"#{Webpacker.config.source_entry_path}/hello_svelte.js"
|
18
|
+
|
19
|
+
say "Copying Svelte app file to #{Webpacker.config.source_path}"
|
20
|
+
copy_file "#{__dir__}/examples/svelte/app.svelte",
|
21
|
+
"#{Webpacker.config.source_path}/app.svelte"
|
22
|
+
|
23
|
+
say "Installing all Svelte dependencies"
|
24
|
+
run "yarn add svelte svelte-loader"
|
25
|
+
|
26
|
+
say "Updating webpack paths to include .svelte file extension"
|
27
|
+
insert_into_file Webpacker.config.config_path, "- .svelte\n".indent(4), after: /\s+extensions:\n/
|
28
|
+
|
29
|
+
say "Webpacker now supports Svelte 🎉", :green
|