jetpacker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +11 -11
- data/.node-version +1 -0
- data/.rubocop.yml +125 -0
- data/.travis.yml +54 -5
- data/CHANGELOG.jetpacker.md +7 -0
- data/CHANGELOG.md +1000 -0
- data/CONTRIBUTING.md +33 -0
- data/Gemfile +9 -3
- data/Gemfile.lock +157 -21
- data/MIT-LICENSE +20 -0
- data/README.md +671 -16
- data/Rakefile +8 -3
- data/docs/assets.md +119 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +253 -0
- data/docs/deployment.md +130 -0
- data/docs/docker.md +68 -0
- data/docs/engines.md +200 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +72 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +137 -0
- data/docs/troubleshooting.md +156 -0
- data/docs/typescript.md +126 -0
- data/docs/v4-upgrade.md +142 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +364 -0
- data/docs/yarn.md +23 -0
- data/gemfiles/Gemfile-rails-edge +12 -0
- data/gemfiles/Gemfile-rails.4.2.x +9 -0
- data/gemfiles/Gemfile-rails.5.0.x +9 -0
- data/gemfiles/Gemfile-rails.5.1.x +9 -0
- data/gemfiles/Gemfile-rails.5.2.x +9 -0
- data/gemfiles/Gemfile-rails.6.0.x +9 -0
- data/jetpacker.gemspec +28 -22
- data/lib/install/angular.rb +23 -0
- data/lib/install/bin/webpack +18 -0
- data/lib/install/bin/webpack-dev-server +18 -0
- data/lib/install/binstubs.rb +4 -0
- data/lib/install/coffee.rb +25 -0
- data/lib/install/config/.browserslistrc +1 -0
- data/lib/install/config/babel.config.js +72 -0
- data/lib/install/config/postcss.config.js +12 -0
- data/lib/install/config/webpack/development.js +5 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +5 -0
- data/lib/install/config/webpack/test.js +5 -0
- data/lib/install/config/webpacker.yml +96 -0
- data/lib/install/elm.rb +39 -0
- data/lib/install/erb.rb +25 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +55 -0
- data/lib/install/examples/elm/hello_elm.js +16 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/babel.config.js +87 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/react/tsconfig.json +20 -0
- data/lib/install/examples/stimulus/application.js +1 -0
- data/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
- data/lib/install/examples/stimulus/controllers/index.js +9 -0
- data/lib/install/examples/svelte/app.svelte +11 -0
- data/lib/install/examples/svelte/hello_svelte.js +20 -0
- data/lib/install/examples/typescript/hello_typescript.ts +4 -0
- data/lib/install/examples/typescript/tsconfig.json +23 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +72 -0
- data/lib/install/javascript/packs/application.js +18 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +25 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/svelte.js +9 -0
- data/lib/install/loaders/typescript.js +11 -0
- data/lib/install/loaders/vue.js +6 -0
- data/lib/install/react.rb +18 -0
- data/lib/install/stimulus.rb +12 -0
- data/lib/install/svelte.rb +29 -0
- data/lib/install/template.rb +55 -0
- data/lib/install/typescript.rb +46 -0
- data/lib/install/vue.rb +49 -0
- data/lib/jetpacker/version.rb +2 -1
- data/lib/tasks/installers.rake +37 -0
- data/lib/tasks/webpacker.rake +28 -0
- data/lib/tasks/webpacker/binstubs.rake +11 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clean.rake +21 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +43 -0
- data/lib/tasks/webpacker/info.rake +20 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +13 -0
- data/lib/tasks/webpacker/yarn_install.rake +21 -0
- data/lib/webpacker.rb +46 -0
- data/lib/webpacker/commands.rb +50 -0
- data/lib/webpacker/compiler.rb +107 -0
- data/lib/webpacker/configuration.rb +113 -0
- data/lib/webpacker/dev_server.rb +66 -0
- data/lib/webpacker/dev_server_proxy.rb +31 -0
- data/lib/webpacker/dev_server_runner.rb +72 -0
- data/lib/webpacker/env.rb +39 -0
- data/lib/webpacker/helper.rb +176 -0
- data/lib/webpacker/instance.rb +37 -0
- data/lib/webpacker/manifest.rb +118 -0
- data/lib/webpacker/railtie.rb +98 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +4 -0
- data/lib/webpacker/webpack_runner.rb +32 -0
- data/package.json +82 -0
- data/package/__tests__/config.js +55 -0
- data/package/__tests__/dev_server.js +43 -0
- data/package/__tests__/development.js +30 -0
- data/package/__tests__/env.js +46 -0
- data/package/__tests__/production.js +29 -0
- data/package/__tests__/staging.js +29 -0
- data/package/__tests__/test.js +26 -0
- data/package/config.js +37 -0
- data/package/config_types/__tests__/config_list.js +118 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +75 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/dev_server.js +20 -0
- data/package/env.js +19 -0
- data/package/environments/__tests__/base.js +74 -0
- data/package/environments/base.js +166 -0
- data/package/environments/development.js +51 -0
- data/package/environments/production.js +79 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +24 -0
- data/package/rules/babel.js +21 -0
- data/package/rules/css.js +3 -0
- data/package/rules/file.js +20 -0
- data/package/rules/index.js +20 -0
- data/package/rules/module.css.js +3 -0
- data/package/rules/module.sass.js +8 -0
- data/package/rules/node_modules.js +24 -0
- data/package/rules/sass.js +8 -0
- data/package/utils/__tests__/deep_assign.js +32 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/get_style_rule.js +65 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +22 -0
- data/package/utils/get_style_rule.js +45 -0
- data/package/utils/helpers.js +58 -0
- data/package/utils/objectify.js +3 -0
- data/test/command_test.rb +33 -0
- data/test/compiler_test.rb +75 -0
- data/test/configuration_test.rb +108 -0
- data/test/dev_server_runner_test.rb +51 -0
- data/test/dev_server_test.rb +47 -0
- data/test/env_test.rb +23 -0
- data/test/helper_test.rb +142 -0
- data/test/manifest_test.rb +42 -0
- data/test/rake_tasks_test.rb +69 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/bin/webpack +14 -0
- data/test/test_app/bin/webpack-dev-server +14 -0
- data/test/test_app/config.ru +5 -0
- data/test/test_app/config/application.rb +12 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpack/development.js +0 -0
- data/test/test_app/config/webpacker.yml +97 -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 +31 -0
- data/test/test_app/yarn.lock +11 -0
- data/test/test_helper.rb +33 -0
- data/test/webpack_runner_test.rb +51 -0
- data/test/webpacker_test.rb +13 -0
- data/yarn.lock +8321 -0
- metadata +267 -29
- data/.rspec +0 -3
- data/LICENSE.txt +0 -21
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/lib/jetpacker.rb +0 -6
@@ -0,0 +1,98 @@
|
|
1
|
+
require "rails/railtie"
|
2
|
+
|
3
|
+
require "webpacker/helper"
|
4
|
+
require "webpacker/dev_server_proxy"
|
5
|
+
|
6
|
+
class Webpacker::Engine < ::Rails::Engine
|
7
|
+
# Allows Webpacker config values to be set via Rails env config files
|
8
|
+
config.webpacker = ActiveSupport::OrderedOptions.new
|
9
|
+
|
10
|
+
initializer "webpacker.set_configs" do |app|
|
11
|
+
if app.config.webpacker.key?(:check_yarn_integrity)
|
12
|
+
Webpacker.config.check_yarn_integrity = app.config.webpacker.check_yarn_integrity
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# ================================
|
17
|
+
# Check Yarn Integrity Initializer
|
18
|
+
# ================================
|
19
|
+
#
|
20
|
+
# development (on by default):
|
21
|
+
#
|
22
|
+
# to turn off:
|
23
|
+
# - edit config/environments/development.rb
|
24
|
+
# - add `config.webpacker.check_yarn_integrity = false`
|
25
|
+
#
|
26
|
+
# production (off by default):
|
27
|
+
#
|
28
|
+
# to turn on:
|
29
|
+
# - edit config/environments/production.rb
|
30
|
+
# - add `config.webpacker.check_yarn_integrity = true`
|
31
|
+
initializer "webpacker.yarn_check" do |app|
|
32
|
+
if File.exist?("yarn.lock") && Webpacker.config.config_path.exist? && Webpacker.config.check_yarn_integrity?
|
33
|
+
output = `yarn check --integrity && yarn check --verify-tree 2>&1`
|
34
|
+
|
35
|
+
unless $?.success?
|
36
|
+
$stderr.puts "\n\n"
|
37
|
+
$stderr.puts "========================================"
|
38
|
+
$stderr.puts " Your Yarn packages are out of date!"
|
39
|
+
$stderr.puts " Please run `yarn install --check-files` to update."
|
40
|
+
$stderr.puts "========================================"
|
41
|
+
$stderr.puts "\n\n"
|
42
|
+
$stderr.puts "To disable this check, please change `check_yarn_integrity`"
|
43
|
+
$stderr.puts "to `false` in your webpacker config file (config/webpacker.yml)."
|
44
|
+
$stderr.puts "\n\n"
|
45
|
+
$stderr.puts output
|
46
|
+
$stderr.puts "\n\n"
|
47
|
+
|
48
|
+
exit(1)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
initializer "webpacker.proxy" do |app|
|
54
|
+
insert_middleware = Webpacker.config.dev_server.present? rescue nil
|
55
|
+
if insert_middleware
|
56
|
+
app.middleware.insert_before 0,
|
57
|
+
Rails::VERSION::MAJOR >= 5 ?
|
58
|
+
Webpacker::DevServerProxy : "Webpacker::DevServerProxy", ssl_verify_none: true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
initializer "webpacker.helper" do
|
63
|
+
ActiveSupport.on_load :action_controller do
|
64
|
+
ActionController::Base.helper Webpacker::Helper
|
65
|
+
end
|
66
|
+
|
67
|
+
ActiveSupport.on_load :action_view do
|
68
|
+
include Webpacker::Helper
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
initializer "webpacker.logger" do
|
73
|
+
config.after_initialize do
|
74
|
+
if ::Rails.logger.respond_to?(:tagged)
|
75
|
+
Webpacker.logger = ::Rails.logger
|
76
|
+
else
|
77
|
+
Webpacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
initializer "webpacker.bootstrap" do
|
83
|
+
if defined?(Rails::Server) || defined?(Rails::Console)
|
84
|
+
Webpacker.bootstrap
|
85
|
+
if defined?(Spring)
|
86
|
+
require "spring/watcher"
|
87
|
+
Spring.after_fork { Webpacker.bootstrap }
|
88
|
+
Spring.watch(Webpacker.config.config_path)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
initializer "webpacker.set_source" do |app|
|
94
|
+
if Webpacker.config.config_path.exist?
|
95
|
+
app.config.javascript_path = Webpacker.config.source_path.relative_path_from(Rails.root.join("app")).to_s
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Webpacker
|
2
|
+
class Runner
|
3
|
+
def self.run(argv)
|
4
|
+
$stdout.sync = true
|
5
|
+
|
6
|
+
new(argv).run
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(argv)
|
10
|
+
@argv = argv
|
11
|
+
|
12
|
+
@app_path = File.expand_path(".", Dir.pwd)
|
13
|
+
@node_modules_bin_path = ENV["WEBPACKER_NODE_MODULES_BIN_PATH"] || `yarn bin`.chomp
|
14
|
+
@webpack_config = File.join(@app_path, "config/webpack/#{ENV["NODE_ENV"]}.js")
|
15
|
+
|
16
|
+
unless File.exist?(@webpack_config)
|
17
|
+
$stderr.puts "webpack config #{@webpack_config} not found, please run 'bundle exec rails webpacker:install' to install Webpacker with default configs or add the missing config file for your custom environment."
|
18
|
+
exit!
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "shellwords"
|
2
|
+
require "webpacker/runner"
|
3
|
+
|
4
|
+
module Webpacker
|
5
|
+
class WebpackRunner < Webpacker::Runner
|
6
|
+
def run
|
7
|
+
env = Webpacker::Compiler.env
|
8
|
+
|
9
|
+
cmd = if node_modules_bin_exist?
|
10
|
+
["#{@node_modules_bin_path}/webpack"]
|
11
|
+
else
|
12
|
+
["yarn", "webpack"]
|
13
|
+
end
|
14
|
+
|
15
|
+
if ARGV.include?("--debug")
|
16
|
+
cmd = [ "node", "--inspect-brk"] + cmd
|
17
|
+
ARGV.delete("--debug")
|
18
|
+
end
|
19
|
+
|
20
|
+
cmd += ["--config", @webpack_config] + @argv
|
21
|
+
|
22
|
+
Dir.chdir(@app_path) do
|
23
|
+
Kernel.exec env, *cmd
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def node_modules_bin_exist?
|
29
|
+
File.exist?("#{@node_modules_bin_path}/webpack")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/package.json
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
{
|
2
|
+
"name": "@rails/webpacker",
|
3
|
+
"version": "4.2.2",
|
4
|
+
"description": "Use webpack to manage app-like JavaScript modules in Rails",
|
5
|
+
"main": "package/index.js",
|
6
|
+
"files": [
|
7
|
+
"package",
|
8
|
+
"lib/install/config/webpacker.yml"
|
9
|
+
],
|
10
|
+
"engines": {
|
11
|
+
"node": ">=8.16.0",
|
12
|
+
"yarn": ">=1.0.0"
|
13
|
+
},
|
14
|
+
"dependencies": {
|
15
|
+
"@babel/core": "^7.7.2",
|
16
|
+
"@babel/plugin-proposal-class-properties": "^7.7.0",
|
17
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
|
18
|
+
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
19
|
+
"@babel/plugin-transform-destructuring": "^7.6.0",
|
20
|
+
"@babel/plugin-transform-regenerator": "^7.7.0",
|
21
|
+
"@babel/plugin-transform-runtime": "^7.6.2",
|
22
|
+
"@babel/preset-env": "^7.7.1",
|
23
|
+
"@babel/runtime": "^7.7.2",
|
24
|
+
"babel-loader": "^8.0.6",
|
25
|
+
"babel-plugin-dynamic-import-node": "^2.3.0",
|
26
|
+
"babel-plugin-macros": "^2.6.1",
|
27
|
+
"case-sensitive-paths-webpack-plugin": "^2.2.0",
|
28
|
+
"compression-webpack-plugin": "^3.0.1",
|
29
|
+
"core-js": "^3.4.0",
|
30
|
+
"css-loader": "^3.2.0",
|
31
|
+
"file-loader": "^4.2.0",
|
32
|
+
"flatted": "^2.0.1",
|
33
|
+
"glob": "^7.1.6",
|
34
|
+
"js-yaml": "^3.13.1",
|
35
|
+
"mini-css-extract-plugin": "^0.8.0",
|
36
|
+
"node-sass": "^4.13.0",
|
37
|
+
"optimize-css-assets-webpack-plugin": "^5.0.3",
|
38
|
+
"path-complete-extname": "^1.0.0",
|
39
|
+
"pnp-webpack-plugin": "^1.5.0",
|
40
|
+
"postcss-flexbugs-fixes": "^4.1.0",
|
41
|
+
"postcss-import": "^12.0.1",
|
42
|
+
"postcss-loader": "^3.0.0",
|
43
|
+
"postcss-preset-env": "^6.7.0",
|
44
|
+
"postcss-safe-parser": "^4.0.1",
|
45
|
+
"regenerator-runtime": "^0.13.3",
|
46
|
+
"sass-loader": "7.3.1",
|
47
|
+
"style-loader": "^1.0.0",
|
48
|
+
"terser-webpack-plugin": "^2.3.1",
|
49
|
+
"webpack": "^4.41.3",
|
50
|
+
"webpack-assets-manifest": "^3.1.1",
|
51
|
+
"webpack-cli": "^3.3.10",
|
52
|
+
"webpack-sources": "^1.4.3"
|
53
|
+
},
|
54
|
+
"devDependencies": {
|
55
|
+
"eslint": "^6.6.0",
|
56
|
+
"eslint-config-airbnb": "^18.0.1",
|
57
|
+
"eslint-plugin-import": "^2.18.2",
|
58
|
+
"eslint-plugin-jsx-a11y": "^6.2.3",
|
59
|
+
"eslint-plugin-react": "^7.16.0",
|
60
|
+
"jest": "^24.9.0"
|
61
|
+
},
|
62
|
+
"jest": {
|
63
|
+
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
|
64
|
+
"roots": [
|
65
|
+
"<rootDir>/package"
|
66
|
+
]
|
67
|
+
},
|
68
|
+
"scripts": {
|
69
|
+
"test": "jest",
|
70
|
+
"lint": "eslint package/"
|
71
|
+
},
|
72
|
+
"repository": {
|
73
|
+
"type": "git",
|
74
|
+
"url": "git+https://github.com/rails/webpacker.git"
|
75
|
+
},
|
76
|
+
"author": "David Heinemeier Hansson <david@basecamp.com>",
|
77
|
+
"license": "MIT",
|
78
|
+
"bugs": {
|
79
|
+
"url": "https://github.com/rails/webpacker/issues"
|
80
|
+
},
|
81
|
+
"homepage": "https://github.com/rails/webpacker"
|
82
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
/* global test expect, describe */
|
2
|
+
|
3
|
+
const { chdirCwd, chdirTestApp, resetEnv } = require('../utils/helpers')
|
4
|
+
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
const config = require('../config')
|
8
|
+
|
9
|
+
describe('Config', () => {
|
10
|
+
beforeEach(() => jest.resetModules() && resetEnv())
|
11
|
+
afterAll(chdirCwd)
|
12
|
+
|
13
|
+
test('public path', () => {
|
14
|
+
process.env.RAILS_ENV = 'development'
|
15
|
+
const config = require('../config')
|
16
|
+
expect(config.publicPath).toEqual('/packs/')
|
17
|
+
})
|
18
|
+
|
19
|
+
test('public path with asset host', () => {
|
20
|
+
process.env.RAILS_ENV = 'development'
|
21
|
+
process.env.WEBPACKER_ASSET_HOST = 'http://foo.com/'
|
22
|
+
const config = require('../config')
|
23
|
+
expect(config.publicPath).toEqual('http://foo.com/packs/')
|
24
|
+
})
|
25
|
+
|
26
|
+
test('should return extensions as listed in app config', () => {
|
27
|
+
expect(config.extensions).toEqual([
|
28
|
+
'.mjs',
|
29
|
+
'.js',
|
30
|
+
'.sass',
|
31
|
+
'.scss',
|
32
|
+
'.css',
|
33
|
+
'.module.sass',
|
34
|
+
'.module.scss',
|
35
|
+
'.module.css',
|
36
|
+
'.png',
|
37
|
+
'.svg',
|
38
|
+
'.gif',
|
39
|
+
'.jpeg',
|
40
|
+
'.jpg'
|
41
|
+
])
|
42
|
+
})
|
43
|
+
|
44
|
+
test('should return static assets extensions as listed in app config', () => {
|
45
|
+
expect(config.static_assets_extensions).toEqual([
|
46
|
+
'.jpg',
|
47
|
+
'.jpeg',
|
48
|
+
'.png',
|
49
|
+
'.gif',
|
50
|
+
'.tiff',
|
51
|
+
'.ico',
|
52
|
+
'.svg',
|
53
|
+
])
|
54
|
+
})
|
55
|
+
})
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/* global test expect, describe */
|
2
|
+
|
3
|
+
const { chdirTestApp, chdirCwd } = require('../utils/helpers')
|
4
|
+
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe('DevServer', () => {
|
8
|
+
beforeEach(() => jest.resetModules())
|
9
|
+
afterAll(chdirCwd)
|
10
|
+
|
11
|
+
test('with NODE_ENV and RAILS_ENV set to development', () => {
|
12
|
+
process.env.NODE_ENV = 'development'
|
13
|
+
process.env.RAILS_ENV = 'development'
|
14
|
+
process.env.WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
|
15
|
+
process.env.WEBPACKER_DEV_SERVER_PORT = 5000
|
16
|
+
|
17
|
+
const devServer = require('../dev_server')
|
18
|
+
expect(devServer).toBeDefined()
|
19
|
+
expect(devServer.host).toEqual('0.0.0.0')
|
20
|
+
expect(devServer.port).toEqual('5000')
|
21
|
+
})
|
22
|
+
|
23
|
+
test('with custom env prefix', () => {
|
24
|
+
const config = require('../config')
|
25
|
+
config.dev_server.env_prefix = 'TEST_WEBPACKER_DEV_SERVER'
|
26
|
+
|
27
|
+
process.env.NODE_ENV = 'development'
|
28
|
+
process.env.RAILS_ENV = 'development'
|
29
|
+
process.env.TEST_WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
|
30
|
+
process.env.TEST_WEBPACKER_DEV_SERVER_PORT = 5000
|
31
|
+
|
32
|
+
const devServer = require('../dev_server')
|
33
|
+
expect(devServer).toBeDefined()
|
34
|
+
expect(devServer.host).toEqual('0.0.0.0')
|
35
|
+
expect(devServer.port).toEqual('5000')
|
36
|
+
})
|
37
|
+
|
38
|
+
test('with NODE_ENV and RAILS_ENV set to production', () => {
|
39
|
+
process.env.RAILS_ENV = 'production'
|
40
|
+
process.env.NODE_ENV = 'production'
|
41
|
+
expect(require('../dev_server')).toEqual({})
|
42
|
+
})
|
43
|
+
})
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/* test expect, describe, afterAll, beforeEach */
|
2
|
+
|
3
|
+
const { resolve } = require('path')
|
4
|
+
const { chdirTestApp, chdirCwd } = require('../utils/helpers')
|
5
|
+
|
6
|
+
chdirTestApp()
|
7
|
+
|
8
|
+
describe('Development environment', () => {
|
9
|
+
afterAll(chdirCwd)
|
10
|
+
|
11
|
+
describe('toWebpackConfig', () => {
|
12
|
+
beforeEach(() => jest.resetModules())
|
13
|
+
|
14
|
+
test('should use development config and environment', () => {
|
15
|
+
process.env.RAILS_ENV = 'development'
|
16
|
+
process.env.NODE_ENV = 'development'
|
17
|
+
const { environment } = require('../index')
|
18
|
+
|
19
|
+
const config = environment.toWebpackConfig()
|
20
|
+
expect(config.output.path).toEqual(resolve('public', 'packs'))
|
21
|
+
expect(config.output.publicPath).toEqual('/packs/')
|
22
|
+
expect(config).toMatchObject({
|
23
|
+
devServer: {
|
24
|
+
host: 'localhost',
|
25
|
+
port: 3035
|
26
|
+
}
|
27
|
+
})
|
28
|
+
})
|
29
|
+
})
|
30
|
+
})
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/* global test expect, describe */
|
2
|
+
|
3
|
+
const { chdirTestApp, chdirCwd } = require('../utils/helpers')
|
4
|
+
|
5
|
+
chdirTestApp()
|
6
|
+
|
7
|
+
describe('Env', () => {
|
8
|
+
beforeEach(() => jest.resetModules())
|
9
|
+
afterAll(chdirCwd)
|
10
|
+
|
11
|
+
test('with NODE_ENV and RAILS_ENV set to development', () => {
|
12
|
+
process.env.RAILS_ENV = 'development'
|
13
|
+
process.env.NODE_ENV = 'development'
|
14
|
+
expect(require('../env')).toEqual({
|
15
|
+
railsEnv: 'development',
|
16
|
+
nodeEnv: 'development'
|
17
|
+
})
|
18
|
+
})
|
19
|
+
|
20
|
+
test('with undefined NODE_ENV and RAILS_ENV set to development', () => {
|
21
|
+
process.env.RAILS_ENV = 'development'
|
22
|
+
delete process.env.NODE_ENV
|
23
|
+
expect(require('../env')).toEqual({
|
24
|
+
railsEnv: 'development',
|
25
|
+
nodeEnv: 'production'
|
26
|
+
})
|
27
|
+
})
|
28
|
+
|
29
|
+
test('with undefined NODE_ENV and RAILS_ENV', () => {
|
30
|
+
delete process.env.NODE_ENV
|
31
|
+
delete process.env.RAILS_ENV
|
32
|
+
expect(require('../env')).toEqual({
|
33
|
+
railsEnv: 'production',
|
34
|
+
nodeEnv: 'production'
|
35
|
+
})
|
36
|
+
})
|
37
|
+
|
38
|
+
test('with a non-standard environment', () => {
|
39
|
+
process.env.RAILS_ENV = 'staging'
|
40
|
+
process.env.NODE_ENV = 'staging'
|
41
|
+
expect(require('../env')).toEqual({
|
42
|
+
railsEnv: 'staging',
|
43
|
+
nodeEnv: 'production'
|
44
|
+
})
|
45
|
+
})
|
46
|
+
})
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/* test expect, describe, afterAll, beforeEach */
|
2
|
+
|
3
|
+
const { resolve } = require('path')
|
4
|
+
const { chdirTestApp, chdirCwd } = require('../utils/helpers')
|
5
|
+
|
6
|
+
chdirTestApp()
|
7
|
+
|
8
|
+
describe('Production environment', () => {
|
9
|
+
afterAll(chdirCwd)
|
10
|
+
|
11
|
+
describe('toWebpackConfig', () => {
|
12
|
+
beforeEach(() => jest.resetModules())
|
13
|
+
|
14
|
+
test('should use production config and environment', () => {
|
15
|
+
process.env.RAILS_ENV = 'production'
|
16
|
+
process.env.NODE_ENV = 'production'
|
17
|
+
|
18
|
+
const { environment } = require('../index')
|
19
|
+
const config = environment.toWebpackConfig()
|
20
|
+
|
21
|
+
expect(config.output.path).toEqual(resolve('public', 'packs'))
|
22
|
+
expect(config.output.publicPath).toEqual('/packs/')
|
23
|
+
expect(config).toMatchObject({
|
24
|
+
devtool: 'source-map',
|
25
|
+
stats: 'normal'
|
26
|
+
})
|
27
|
+
})
|
28
|
+
})
|
29
|
+
})
|