webpacker 3.3.1 → 3.4.0
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/.gitignore +1 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +54 -3
- data/docs/testing.md +9 -0
- data/lib/install/bin/webpack +1 -1
- data/lib/install/bin/webpack-dev-server +1 -1
- data/lib/install/config/webpack/development.js +2 -0
- data/lib/install/config/webpack/production.js +2 -0
- data/lib/install/config/webpack/test.js +2 -0
- data/lib/tasks/webpacker/compile.rake +2 -0
- data/lib/webpacker/compiler.rb +1 -2
- data/lib/webpacker/dev_server_runner.rb +2 -2
- data/lib/webpacker/env.rb +2 -2
- data/lib/webpacker/railtie.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/package.json +1 -1
- data/package/__tests__/dev_server.js +4 -2
- data/package/__tests__/development.js +30 -0
- data/package/__tests__/env.js +26 -8
- data/package/__tests__/production.js +27 -0
- data/package/__tests__/staging.js +27 -0
- data/package/__tests__/test.js +23 -0
- data/package/config.js +12 -14
- data/package/dev_server.js +8 -13
- data/package/env.js +10 -14
- data/package/environments/__tests__/base.js +0 -2
- data/package/index.js +2 -2
- data/package/utils/get_style_rule.js +2 -1
- data/test/configuration_test.rb +10 -14
- data/test/dev_server_test.rb +4 -10
- data/test/env_test.rb +10 -6
- data/test/test_app/config/webpacker.yml +12 -0
- data/test/test_helper.rb +7 -5
- metadata +6 -3
- data/package/__tests__/index.js +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5470791c43b6592ccb7695fea1838c1f09cf8df2072da5be33c26c1f5e3d2212
|
4
|
+
data.tar.gz: 4c422b0d744013934cb67bd79995bf408a10143dcdedf93d934dbf99854a8706
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 785e7b6fa02e9e0459956c634a8cb59f59baae743a6fb3a43c8831406265f8dc6f2f56dedd51076afa1448ab239c8e22dfc81cf8d4cb06bf80f1092d7a480867
|
7
|
+
data.tar.gz: 8117b275c4135c4dbe64ab40123bb9b5855b8303ab1c64036ca3f71b26eac729437c43574b52682300710bf47cd512ea792de005cabcfbcbbfc511ef20e66626
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
**Please note that Webpacker 3.1.0 and 3.1.1 has some serious bugs so please consider using either 3.0.2 or 3.2.0**
|
2
2
|
|
3
|
+
## [3.4.0] - 2018-03-23
|
4
|
+
|
5
|
+
## Added
|
6
|
+
- Support for custom Rails environments [#1359](https://github.com/rails/webpacker/pull/1359)
|
7
|
+
|
8
|
+
*This could break the compilation if you set NODE_ENV to custom environment. Now, NODE_ENV only understands production or development mode*
|
9
|
+
|
10
|
+
|
3
11
|
## [3.3.1] - 2018-03-12
|
4
12
|
|
5
13
|
## Fixed
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,8 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
22
22
|
- [Installation](#installation)
|
23
23
|
- [Usage](#usage)
|
24
24
|
- [Development](#development)
|
25
|
-
- [
|
25
|
+
- [Webpack Configuration](#webpack-configuration)
|
26
|
+
- [Custom Rails environments](#custom-rails-environments)
|
26
27
|
- [Upgrading](#upgrading)
|
27
28
|
- [Yarn Integrity](#yarn-integrity)
|
28
29
|
- [Integrations](#integrations)
|
@@ -190,11 +191,61 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
190
191
|
|
191
192
|
**Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
|
192
193
|
|
193
|
-
###
|
194
|
+
### Webpack Configuration
|
194
195
|
|
195
196
|
See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
|
196
197
|
|
197
198
|
|
199
|
+
### Custom Rails environments
|
200
|
+
|
201
|
+
Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
|
202
|
+
|
203
|
+
You can choose to define additional environment configurations in webpacker.yml,
|
204
|
+
|
205
|
+
```yml
|
206
|
+
staging:
|
207
|
+
<<: *default
|
208
|
+
|
209
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
210
|
+
compile: false
|
211
|
+
|
212
|
+
# Cache manifest.json for performance
|
213
|
+
cache_manifest: true
|
214
|
+
|
215
|
+
# Compile staging packs to a separate directory
|
216
|
+
public_output_path: packs-staging
|
217
|
+
```
|
218
|
+
|
219
|
+
or, Webpacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production` or `development`.
|
220
|
+
This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
|
221
|
+
|
222
|
+
For example, the below command will compile assets in production mode but will use staging configurations from `config/webpacker.yml` if available or use fallback production environment configuration:
|
223
|
+
|
224
|
+
```bash
|
225
|
+
RAILS_ENV=staging bundle exec rails assets:precompile
|
226
|
+
```
|
227
|
+
|
228
|
+
And, this will compile in development mode and load configuration for cucumber environment
|
229
|
+
if defined in webpacker.yml or fallback to production configuration
|
230
|
+
|
231
|
+
```bash
|
232
|
+
RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
|
233
|
+
```
|
234
|
+
|
235
|
+
Please note, binstubs compiles in development mode however rake tasks
|
236
|
+
compiles in production mode.
|
237
|
+
|
238
|
+
```bash
|
239
|
+
# Compiles in development mode unless NODE_ENV is specified
|
240
|
+
./bin/webpack
|
241
|
+
./bin/webpack-dev-server
|
242
|
+
|
243
|
+
# compiles in production mode by default unless NODE_ENV is specified
|
244
|
+
bundle exec rails assets:precompile
|
245
|
+
bundle exec rails webpacker:compile
|
246
|
+
```
|
247
|
+
|
248
|
+
|
198
249
|
### Upgrading
|
199
250
|
|
200
251
|
You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related npm modules:
|
@@ -202,7 +253,7 @@ You can run following commands to upgrade Webpacker to the latest stable version
|
|
202
253
|
```bash
|
203
254
|
bundle update webpacker
|
204
255
|
yarn upgrade @rails/webpacker --latest
|
205
|
-
yarn
|
256
|
+
yarn add webpack-dev-server@^2.11.1
|
206
257
|
```
|
207
258
|
|
208
259
|
### Yarn Integrity
|
data/docs/testing.md
CHANGED
@@ -126,3 +126,12 @@ class HomesTest < ApplicationSystemTestCase
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
```
|
129
|
+
|
130
|
+
## Capybara setup for Rails
|
131
|
+
Make sure you configure Rails to serve static files from the public directory in the test environment.
|
132
|
+
|
133
|
+
```rb
|
134
|
+
# config/environments/test.rb
|
135
|
+
# Configure public file server for tests with Cache-Control for performance.
|
136
|
+
config.public_file_server.enabled = true
|
137
|
+
```
|
data/lib/install/bin/webpack
CHANGED
data/lib/webpacker/compiler.rb
CHANGED
@@ -78,8 +78,7 @@ class Webpacker::Compiler
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def webpack_env
|
81
|
-
env.merge("
|
82
|
-
"WEBPACKER_ASSET_HOST" => ActionController::Base.helpers.compute_asset_host,
|
81
|
+
env.merge("WEBPACKER_ASSET_HOST" => ActionController::Base.helpers.compute_asset_host,
|
83
82
|
"WEBPACKER_RELATIVE_URL_ROOT" => ActionController::Base.relative_url_root)
|
84
83
|
end
|
85
84
|
end
|
@@ -14,14 +14,14 @@ module Webpacker
|
|
14
14
|
private
|
15
15
|
def load_config
|
16
16
|
@config_file = File.join(@app_path, "config/webpacker.yml")
|
17
|
-
dev_server = YAML.load_file(@config_file)[ENV["
|
17
|
+
dev_server = YAML.load_file(@config_file)[ENV["RAILS_ENV"]]["dev_server"]
|
18
18
|
|
19
19
|
@hostname = dev_server["host"]
|
20
20
|
@port = dev_server["port"]
|
21
21
|
@pretty = dev_server.fetch("pretty", true)
|
22
22
|
|
23
23
|
rescue Errno::ENOENT, NoMethodError
|
24
|
-
$stdout.puts "webpack dev_server configuration not found in #{@config_file}."
|
24
|
+
$stdout.puts "webpack dev_server configuration not found in #{@config_file}[#{ENV["RAILS_ENV"]}]."
|
25
25
|
$stdout.puts "Please run bundle exec rails webpacker:install to install Webpacker"
|
26
26
|
exit!
|
27
27
|
end
|
data/lib/webpacker/env.rb
CHANGED
@@ -18,11 +18,11 @@ class Webpacker::Env
|
|
18
18
|
|
19
19
|
private
|
20
20
|
def current
|
21
|
-
|
21
|
+
Rails.env.presence_in(available_environments)
|
22
22
|
end
|
23
23
|
|
24
24
|
def fallback_env_warning
|
25
|
-
logger.info "
|
25
|
+
logger.info "RAILS_ENV=#{Rails.env} environment is not defined in config/webpacker.yml, falling back to #{DEFAULT} environment"
|
26
26
|
end
|
27
27
|
|
28
28
|
def available_environments
|
data/lib/webpacker/railtie.rb
CHANGED
@@ -22,7 +22,7 @@ class Webpacker::Engine < ::Rails::Engine
|
|
22
22
|
#
|
23
23
|
# to turn on:
|
24
24
|
# - edit config/environments/production.rb
|
25
|
-
# - add `config.webpacker.check_yarn_integrity =
|
25
|
+
# - add `config.webpacker.check_yarn_integrity = true`
|
26
26
|
initializer "webpacker.yarn_check" do |app|
|
27
27
|
if File.exist?("yarn.lock") && app.config.webpacker.check_yarn_integrity
|
28
28
|
output = `yarn check --integrity 2>&1`
|
data/lib/webpacker/version.rb
CHANGED
data/package.json
CHANGED
@@ -8,8 +8,9 @@ describe('DevServer', () => {
|
|
8
8
|
beforeEach(() => jest.resetModules())
|
9
9
|
afterAll(chdirCwd)
|
10
10
|
|
11
|
-
test('with NODE_ENV set to development', () => {
|
11
|
+
test('with NODE_ENV and RAILS_ENV set to development', () => {
|
12
12
|
process.env.NODE_ENV = 'development'
|
13
|
+
process.env.RAILS_ENV = 'development'
|
13
14
|
process.env.WEBPACKER_DEV_SERVER_HOST = '0.0.0.0'
|
14
15
|
process.env.WEBPACKER_DEV_SERVER_PORT = 5000
|
15
16
|
|
@@ -19,7 +20,8 @@ describe('DevServer', () => {
|
|
19
20
|
expect(devServer.port).toEqual('5000')
|
20
21
|
})
|
21
22
|
|
22
|
-
test('with NODE_ENV set to production', () => {
|
23
|
+
test('with NODE_ENV and RAILS_ENV set to production', () => {
|
24
|
+
process.env.RAILS_ENV = 'production'
|
23
25
|
process.env.NODE_ENV = 'production'
|
24
26
|
expect(require('../dev_server')).toEqual({})
|
25
27
|
})
|
@@ -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
|
+
})
|
data/package/__tests__/env.js
CHANGED
@@ -8,21 +8,39 @@ describe('Env', () => {
|
|
8
8
|
beforeEach(() => jest.resetModules())
|
9
9
|
afterAll(chdirCwd)
|
10
10
|
|
11
|
-
test('with NODE_ENV set to development', () => {
|
11
|
+
test('with NODE_ENV and RAILS_ENV set to development', () => {
|
12
|
+
process.env.RAILS_ENV = 'development'
|
12
13
|
process.env.NODE_ENV = 'development'
|
13
|
-
expect(require('../env')).toEqual(
|
14
|
+
expect(require('../env')).toEqual({
|
15
|
+
railsEnv: 'development',
|
16
|
+
nodeEnv: 'development'
|
17
|
+
})
|
14
18
|
})
|
15
19
|
|
16
20
|
test('with undefined NODE_ENV and RAILS_ENV set to development', () => {
|
17
|
-
delete process.env.NODE_ENV
|
18
21
|
process.env.RAILS_ENV = 'development'
|
19
|
-
|
22
|
+
delete process.env.NODE_ENV
|
23
|
+
expect(require('../env')).toEqual({
|
24
|
+
railsEnv: 'development',
|
25
|
+
nodeEnv: 'production'
|
26
|
+
})
|
20
27
|
})
|
21
28
|
|
22
|
-
test('with
|
23
|
-
process.env.NODE_ENV
|
24
|
-
process.env.RAILS_ENV = 'foo'
|
25
|
-
expect(require('../env')).toEqual('production')
|
29
|
+
test('with undefined NODE_ENV and RAILS_ENV', () => {
|
30
|
+
delete process.env.NODE_ENV
|
26
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
|
+
})
|
27
45
|
})
|
28
46
|
})
|
@@ -0,0 +1,27 @@
|
|
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
|
+
const { environment } = require('../index')
|
17
|
+
|
18
|
+
const config = environment.toWebpackConfig()
|
19
|
+
expect(config.output.path).toEqual(resolve('public', 'packs'))
|
20
|
+
expect(config.output.publicPath).toEqual('/packs/')
|
21
|
+
expect(config).toMatchObject({
|
22
|
+
devtool: 'nosources-source-map',
|
23
|
+
stats: 'normal'
|
24
|
+
})
|
25
|
+
})
|
26
|
+
})
|
27
|
+
})
|
@@ -0,0 +1,27 @@
|
|
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('Custom environment', () => {
|
9
|
+
afterAll(chdirCwd)
|
10
|
+
|
11
|
+
describe('toWebpackConfig', () => {
|
12
|
+
beforeEach(() => jest.resetModules())
|
13
|
+
|
14
|
+
test('should use staging config and production environment', () => {
|
15
|
+
process.env.RAILS_ENV = 'staging'
|
16
|
+
const { environment } = require('../index')
|
17
|
+
|
18
|
+
const config = environment.toWebpackConfig()
|
19
|
+
expect(config.output.path).toEqual(resolve('public', 'packs-staging'))
|
20
|
+
expect(config.output.publicPath).toEqual('/packs-staging/')
|
21
|
+
expect(config).toMatchObject({
|
22
|
+
devtool: 'nosources-source-map',
|
23
|
+
stats: 'normal'
|
24
|
+
})
|
25
|
+
})
|
26
|
+
})
|
27
|
+
})
|
@@ -0,0 +1,23 @@
|
|
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('Test environment', () => {
|
9
|
+
afterAll(chdirCwd)
|
10
|
+
|
11
|
+
describe('toWebpackConfig', () => {
|
12
|
+
beforeEach(() => jest.resetModules())
|
13
|
+
|
14
|
+
test('should use test config and production environment', () => {
|
15
|
+
process.env.RAILS_ENV = 'test'
|
16
|
+
const { environment } = require('../index')
|
17
|
+
|
18
|
+
const config = environment.toWebpackConfig()
|
19
|
+
expect(config.output.path).toEqual(resolve('public', 'packs-test'))
|
20
|
+
expect(config.output.publicPath).toEqual('/packs-test/')
|
21
|
+
})
|
22
|
+
})
|
23
|
+
})
|
data/package/config.js
CHANGED
@@ -3,25 +3,23 @@ const { safeLoad } = require('js-yaml')
|
|
3
3
|
const { readFileSync } = require('fs')
|
4
4
|
const deepMerge = require('./utils/deep_merge')
|
5
5
|
const { isArray } = require('./utils/helpers')
|
6
|
-
const
|
6
|
+
const { railsEnv } = require('./env')
|
7
7
|
|
8
8
|
const defaultConfigPath = require.resolve('../lib/install/config/webpacker.yml')
|
9
9
|
const configPath = resolve('config', 'webpacker.yml')
|
10
10
|
|
11
|
-
const
|
12
|
-
const
|
13
|
-
|
14
|
-
|
15
|
-
if (isArray(app.extensions) && app.extensions.length) {
|
16
|
-
delete defaults.extensions
|
17
|
-
}
|
11
|
+
const getDefaultConfig = () => {
|
12
|
+
const defaultConfig = safeLoad(readFileSync(defaultConfigPath), 'utf8')
|
13
|
+
return defaultConfig[railsEnv] || defaultConfig.production
|
14
|
+
}
|
18
15
|
|
19
|
-
|
16
|
+
const defaults = getDefaultConfig()
|
17
|
+
const app = safeLoad(readFileSync(configPath), 'utf8')[railsEnv]
|
20
18
|
|
21
|
-
|
22
|
-
config.publicPath = `/${config.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1')
|
19
|
+
if (isArray(app.extensions) && app.extensions.length) delete defaults.extensions
|
23
20
|
|
24
|
-
|
25
|
-
|
21
|
+
const config = deepMerge(defaults, app)
|
22
|
+
config.outputPath = resolve('public', config.public_output_path)
|
23
|
+
config.publicPath = `/${config.public_output_path}/`.replace(/([^:]\/)\/+/g, '$1')
|
26
24
|
|
27
|
-
module.exports =
|
25
|
+
module.exports = config
|
data/package/dev_server.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const { isBoolean
|
1
|
+
const { isBoolean } = require('./utils/helpers')
|
2
2
|
const config = require('./config')
|
3
3
|
|
4
4
|
const fetch = (key) => {
|
@@ -6,18 +6,13 @@ const fetch = (key) => {
|
|
6
6
|
return isBoolean(value) ? JSON.parse(value) : value
|
7
7
|
}
|
8
8
|
|
9
|
-
const
|
10
|
-
const devServerConfig = config.dev_server
|
9
|
+
const devServerConfig = config.dev_server
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
})
|
18
|
-
}
|
19
|
-
|
20
|
-
return devServerConfig || {}
|
11
|
+
if (devServerConfig) {
|
12
|
+
Object.keys(devServerConfig).forEach((key) => {
|
13
|
+
const envValue = fetch(`WEBPACKER_DEV_SERVER_${key.toUpperCase().replace(/_/g, '')}`)
|
14
|
+
if (envValue) devServerConfig[key] = envValue
|
15
|
+
})
|
21
16
|
}
|
22
17
|
|
23
|
-
module.exports =
|
18
|
+
module.exports = devServerConfig || {}
|
data/package/env.js
CHANGED
@@ -2,22 +2,18 @@ const { resolve } = require('path')
|
|
2
2
|
const { safeLoad } = require('js-yaml')
|
3
3
|
const { readFileSync } = require('fs')
|
4
4
|
|
5
|
+
const NODE_ENVIRONMENTS = ['development', 'production']
|
6
|
+
const DEFAULT = 'production'
|
5
7
|
const configPath = resolve('config', 'webpacker.yml')
|
6
|
-
const DEFAULT_ENV = 'production'
|
7
8
|
|
8
|
-
const
|
9
|
-
|
10
|
-
const railsEnv = process.env.RAILS_ENV
|
11
|
-
const config = safeLoad(readFileSync(configPath), 'utf8')
|
12
|
-
const availableEnvironments = Object.keys(config).join('|')
|
13
|
-
const regex = new RegExp(availableEnvironments, 'g')
|
9
|
+
const railsEnv = process.env.RAILS_ENV
|
10
|
+
const nodeEnv = process.env.NODE_ENV
|
14
11
|
|
15
|
-
|
16
|
-
|
12
|
+
const config = safeLoad(readFileSync(configPath), 'utf8')
|
13
|
+
const availableEnvironments = Object.keys(config).join('|')
|
14
|
+
const regex = new RegExp(availableEnvironments, 'g')
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
module.exports = {
|
17
|
+
railsEnv: railsEnv && railsEnv.match(regex) ? railsEnv : DEFAULT,
|
18
|
+
nodeEnv: nodeEnv && NODE_ENVIRONMENTS.includes(nodeEnv) ? nodeEnv : DEFAULT
|
21
19
|
}
|
22
|
-
|
23
|
-
module.exports = env()
|
@@ -31,8 +31,6 @@ describe('Environment', () => {
|
|
31
31
|
const config = environment.toWebpackConfig()
|
32
32
|
expect(config.output.filename).toEqual('[name]-[chunkhash].js')
|
33
33
|
expect(config.output.chunkFilename).toEqual('[name]-[chunkhash].chunk.js')
|
34
|
-
expect(config.output.path).toEqual(resolve('public', 'packs-test'))
|
35
|
-
expect(config.output.publicPath).toEqual('/packs-test/')
|
36
34
|
})
|
37
35
|
|
38
36
|
test('should return default loader rules for each file in config/loaders', () => {
|
data/package/index.js
CHANGED
@@ -5,12 +5,12 @@ const { resolve } = require('path')
|
|
5
5
|
const { existsSync } = require('fs')
|
6
6
|
const Environment = require('./environments/base')
|
7
7
|
const loaders = require('./rules')
|
8
|
-
const env = require('./env')
|
9
8
|
const config = require('./config')
|
10
9
|
const devServer = require('./dev_server')
|
10
|
+
const { nodeEnv } = require('./env')
|
11
11
|
|
12
12
|
const createEnvironment = () => {
|
13
|
-
const path = resolve(__dirname, 'environments', `${
|
13
|
+
const path = resolve(__dirname, 'environments', `${nodeEnv}.js`)
|
14
14
|
const constructor = existsSync(path) ? require(path) : Environment
|
15
15
|
return new constructor()
|
16
16
|
}
|
@@ -1,9 +1,10 @@
|
|
1
1
|
const ExtractTextPlugin = require('extract-text-webpack-plugin')
|
2
2
|
const path = require('path')
|
3
3
|
const devServer = require('../dev_server')
|
4
|
+
const { nodeEnv } = require('../env')
|
4
5
|
|
5
6
|
const postcssConfigPath = path.resolve(process.cwd(), '.postcssrc.yml')
|
6
|
-
const isProduction =
|
7
|
+
const isProduction = nodeEnv === 'production'
|
7
8
|
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
|
8
9
|
const isHMR = inDevServer && (devServer && devServer.hmr)
|
9
10
|
const extractCSS = !isHMR || isProduction
|
data/test/configuration_test.rb
CHANGED
@@ -41,30 +41,26 @@ class ConfigurationTest < Webpacker::Test
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_cache_manifest?
|
44
|
-
|
45
|
-
refute reloaded_config.cache_manifest?
|
46
|
-
end
|
44
|
+
assert Webpacker.config.cache_manifest?
|
47
45
|
|
48
|
-
|
49
|
-
refute
|
46
|
+
with_rails_env("development") do
|
47
|
+
refute Webpacker.config.cache_manifest?
|
50
48
|
end
|
51
49
|
|
52
|
-
|
53
|
-
|
50
|
+
with_rails_env("test") do
|
51
|
+
refute Webpacker.config.cache_manifest?
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
def test_compile?
|
58
|
-
|
59
|
-
assert reloaded_config.compile?
|
60
|
-
end
|
56
|
+
refute Webpacker.config.compile?
|
61
57
|
|
62
|
-
|
63
|
-
assert
|
58
|
+
with_rails_env("development") do
|
59
|
+
assert Webpacker.config.compile?
|
64
60
|
end
|
65
61
|
|
66
|
-
|
67
|
-
|
62
|
+
with_rails_env("test") do
|
63
|
+
assert Webpacker.config.compile?
|
68
64
|
end
|
69
65
|
end
|
70
66
|
end
|
data/test/dev_server_test.rb
CHANGED
@@ -2,29 +2,23 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
class DevServerTest < Webpacker::Test
|
4
4
|
def test_running?
|
5
|
-
|
6
|
-
reloaded_config
|
7
|
-
refute Webpacker.dev_server.running?
|
8
|
-
end
|
5
|
+
refute Webpacker.dev_server.running?
|
9
6
|
end
|
10
7
|
|
11
8
|
def test_host
|
12
|
-
|
13
|
-
reloaded_config
|
9
|
+
with_rails_env("development") do
|
14
10
|
assert_equal Webpacker.dev_server.host, "localhost"
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
18
14
|
def test_port
|
19
|
-
|
20
|
-
reloaded_config
|
15
|
+
with_rails_env("development") do
|
21
16
|
assert_equal Webpacker.dev_server.port, 3035
|
22
17
|
end
|
23
18
|
end
|
24
19
|
|
25
20
|
def test_https?
|
26
|
-
|
27
|
-
reloaded_config
|
21
|
+
with_rails_env("development") do
|
28
22
|
assert_equal Webpacker.dev_server.https?, false
|
29
23
|
end
|
30
24
|
end
|
data/test/env_test.rb
CHANGED
@@ -2,14 +2,18 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
class EnvTest < Webpacker::Test
|
4
4
|
def test_current
|
5
|
-
|
6
|
-
assert_equal Webpacker.env, "production"
|
5
|
+
assert_equal Webpacker.env, Rails.env
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
def test_custom_without_config
|
9
|
+
with_rails_env("foo") do
|
10
|
+
assert_equal Webpacker.env, "production"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_custom_with_config
|
15
|
+
with_rails_env("staging") do
|
16
|
+
assert_equal Webpacker.env, "staging"
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
@@ -61,3 +61,15 @@ production:
|
|
61
61
|
|
62
62
|
# Cache manifest.json for performance
|
63
63
|
cache_manifest: true
|
64
|
+
|
65
|
+
staging:
|
66
|
+
<<: *default
|
67
|
+
|
68
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
69
|
+
compile: false
|
70
|
+
|
71
|
+
# Cache manifest.json for performance
|
72
|
+
cache_manifest: true
|
73
|
+
|
74
|
+
# Compile staging packs to a separate directory
|
75
|
+
public_output_path: packs-staging
|
data/test/test_helper.rb
CHANGED
@@ -6,7 +6,7 @@ require "byebug"
|
|
6
6
|
|
7
7
|
require_relative "test_app/config/environment"
|
8
8
|
|
9
|
-
|
9
|
+
Rails.env = "production"
|
10
10
|
|
11
11
|
Webpacker.instance = Webpacker::Instance.new \
|
12
12
|
root_path: Pathname.new(File.expand_path("test_app", __dir__)),
|
@@ -21,11 +21,13 @@ class Webpacker::Test < Minitest::Test
|
|
21
21
|
Webpacker.config
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
25
|
-
original =
|
26
|
-
|
24
|
+
def with_rails_env(env)
|
25
|
+
original = Rails.env
|
26
|
+
Rails.env = ActiveSupport::StringInquirer.new(env)
|
27
|
+
reloaded_config
|
27
28
|
yield
|
28
29
|
ensure
|
29
|
-
|
30
|
+
Rails.env = ActiveSupport::StringInquirer.new(original)
|
31
|
+
reloaded_config
|
30
32
|
end
|
31
33
|
end
|
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: 3.
|
4
|
+
version: 3.4.0
|
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: 2018-03-
|
12
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -178,8 +178,11 @@ files:
|
|
178
178
|
- package.json
|
179
179
|
- package/__tests__/config.js
|
180
180
|
- package/__tests__/dev_server.js
|
181
|
+
- package/__tests__/development.js
|
181
182
|
- package/__tests__/env.js
|
182
|
-
- package/__tests__/
|
183
|
+
- package/__tests__/production.js
|
184
|
+
- package/__tests__/staging.js
|
185
|
+
- package/__tests__/test.js
|
183
186
|
- package/config.js
|
184
187
|
- package/config_types/__tests__/config_list.js
|
185
188
|
- package/config_types/__tests__/config_object.js
|
data/package/__tests__/index.js
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
/* global test expect, describe */
|
2
|
-
|
3
|
-
const { chdirTestApp, chdirCwd } = require('../utils/helpers')
|
4
|
-
|
5
|
-
chdirTestApp()
|
6
|
-
|
7
|
-
describe('Webpacker', () => {
|
8
|
-
beforeEach(() => jest.resetModules())
|
9
|
-
afterAll(chdirCwd)
|
10
|
-
|
11
|
-
test('with NODE_ENV set to development', () => {
|
12
|
-
process.env.NODE_ENV = 'development'
|
13
|
-
const { environment } = require('../index')
|
14
|
-
expect(environment.toWebpackConfig()).toMatchObject({
|
15
|
-
devServer: {
|
16
|
-
host: 'localhost',
|
17
|
-
port: 3035
|
18
|
-
}
|
19
|
-
})
|
20
|
-
})
|
21
|
-
|
22
|
-
test('with a non-standard env', () => {
|
23
|
-
process.env.NODE_ENV = 'staging'
|
24
|
-
process.env.RAILS_ENV = 'staging'
|
25
|
-
const { environment } = require('../index')
|
26
|
-
expect(environment.toWebpackConfig()).toMatchObject({
|
27
|
-
devtool: 'nosources-source-map',
|
28
|
-
stats: 'normal'
|
29
|
-
})
|
30
|
-
})
|
31
|
-
})
|