middleman-webpacked 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/features/support/env.rb +1 -1
- data/lib/middleman-webpacked/build.rb +15 -0
- data/lib/middleman-webpacked/command_runner.rb +58 -0
- data/lib/middleman-webpacked/commands/webpack.rb +70 -1
- data/lib/middleman-webpacked/extension.rb +14 -19
- data/lib/middleman-webpacked/server.rb +18 -0
- data/lib/middleman-webpacked/template/babelrc.tt +3 -0
- data/lib/middleman-webpacked/template/dev.webpack.tt +12 -0
- data/lib/middleman-webpacked/template/prod.webpack.tt +6 -0
- data/lib/middleman-webpacked/template/shared.webpack.tt +12 -0
- data/lib/middleman-webpacked/version.rb +1 -1
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba1745c3e19d9181e2bbd1f5e0323ab053e8d0d4
|
4
|
+
data.tar.gz: dd27734e99905e4c9894f639672b632a2f63c40a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2c09955983209d77dd0612b2fe8b085ec64a7ac4115c8441859024834aa99f6a7740d036b9a688cf6a5df16785e185c2eda8ee89b34630047803218d2b36a05
|
7
|
+
data.tar.gz: 62ae18beb74e1ab8b81d98726ea8aeba59e63aeeea7a981c1e3b58af902e807533a3c36ced070258fd2fc511cbcb69c96cf13b669735b063ba60f27696c62406
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Middleman
|
1
|
+
Middleman Webpacked
|
2
2
|
===
|
3
3
|
|
4
4
|
## Usage
|
@@ -15,6 +15,8 @@ Setup your Webpack
|
|
15
15
|
middleman webpack
|
16
16
|
```
|
17
17
|
|
18
|
+
> To enable React.js, add `--react` options when setup Webpack
|
19
|
+
|
18
20
|
Add `javascript_pack_tag` to your layout
|
19
21
|
|
20
22
|
```erb
|
@@ -50,5 +52,6 @@ activate :webpack,
|
|
50
52
|
* [x] Running Webpack without config
|
51
53
|
* [ ] Automatic setup `webpack.config.js`
|
52
54
|
* [x] Babel Support
|
53
|
-
* [
|
55
|
+
* [x] React.js Support
|
54
56
|
* [ ] Vue.js Support
|
57
|
+
* [ ] Sass Support
|
data/features/support/env.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
|
2
2
|
require 'middleman-core'
|
3
3
|
require 'middleman-core/step_definitions'
|
4
|
-
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-
|
4
|
+
require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-webpacked')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module MiddlemanWebpacked
|
2
|
+
class Build < CommandRunner
|
3
|
+
bin 'node_modules/.bin/webpack'
|
4
|
+
mode :production
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@arguments.push(
|
8
|
+
'--bail',
|
9
|
+
'-p',
|
10
|
+
"--output-path #{options.source}/#{app.config[:js_dir]}",
|
11
|
+
"--config config/webpack/production.js"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module MiddlemanWebpacked
|
2
|
+
class CommandRunner
|
3
|
+
class << self
|
4
|
+
AVAILABLE_MODE = %i[production development none]
|
5
|
+
|
6
|
+
def bin(path = nil)
|
7
|
+
return @bin if path.nil?
|
8
|
+
@bin = path
|
9
|
+
end
|
10
|
+
|
11
|
+
def mode(new_mode = nil)
|
12
|
+
return @mode if new_mode.nil?
|
13
|
+
@mode = new_mode if AVAILABLE_MODE.include?(new_mode)
|
14
|
+
end
|
15
|
+
|
16
|
+
def satisfy?
|
17
|
+
return false if bin.nil?
|
18
|
+
File.exist?(bin)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
attr_reader :app, :options, :mode
|
23
|
+
|
24
|
+
def initialize(app, options)
|
25
|
+
@app = app
|
26
|
+
@options = options
|
27
|
+
@arguments = []
|
28
|
+
|
29
|
+
setup
|
30
|
+
end
|
31
|
+
|
32
|
+
def setup
|
33
|
+
raise NotImplementedError, "The command didn't setup for execute"
|
34
|
+
end
|
35
|
+
|
36
|
+
def loaders
|
37
|
+
@loaders.map do |type, loader|
|
38
|
+
"--module-bind #{type}=#{loader}-loader"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def entries
|
43
|
+
options.entry.map do |name, path|
|
44
|
+
"--entry #{name}=./src/#{path}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def command
|
49
|
+
[
|
50
|
+
self.class.bin,
|
51
|
+
"--mode #{self.class.mode}"
|
52
|
+
]
|
53
|
+
.concat(entries)
|
54
|
+
.concat(@arguments)
|
55
|
+
.join(' ')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -5,14 +5,83 @@ module Middleman
|
|
5
5
|
class Webpack < ::Thor::Group
|
6
6
|
include Thor::Actions
|
7
7
|
|
8
|
+
BABEL_TEMPLATE = File.expand_path('../../template/babelrc.tt', __FILE__)
|
9
|
+
SHARED_WEBPACK_TEMPLATE = File.expand_path('../../template/shared.webpack.tt', __FILE__)
|
10
|
+
DEVELOPMENT_WEBPACK_TEMPLATE = File.expand_path('../../template/dev.webpack.tt', __FILE__)
|
11
|
+
PRODUCTION_WEBPACK_TEMPLATE = File.expand_path('../../template/prod.webpack.tt', __FILE__)
|
12
|
+
|
8
13
|
check_unknown_options!
|
9
14
|
|
15
|
+
class_option 'react',
|
16
|
+
type: :boolean,
|
17
|
+
default: false,
|
18
|
+
desc: 'Add react support'
|
19
|
+
|
20
|
+
def self.source_root
|
21
|
+
File.expand_path('../../template', __FILE__)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(*args)
|
25
|
+
super
|
26
|
+
|
27
|
+
@app = ::Middleman::Application.new do
|
28
|
+
config[ :mode ] = :config
|
29
|
+
config[ :disable_sitemap ] = true
|
30
|
+
config[ :watcher_disable ] = true
|
31
|
+
config[ :exit_before_ready ] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
@packages = default_packages
|
35
|
+
end
|
36
|
+
|
10
37
|
def webpack
|
11
|
-
|
38
|
+
@presets = ['env']
|
39
|
+
@loaders = []
|
40
|
+
|
41
|
+
enable_react if options[:react]
|
42
|
+
|
43
|
+
generate_config
|
44
|
+
run "yarn add #{@packages.join(' ')} --dev"
|
45
|
+
end
|
46
|
+
|
47
|
+
def generate_config
|
48
|
+
template BABEL_TEMPLATE, File.join(@app.root_path, '.babelrc')
|
49
|
+
template SHARED_WEBPACK_TEMPLATE, File.join(@app.root_path, 'config', 'webpack', 'shared.js')
|
50
|
+
template DEVELOPMENT_WEBPACK_TEMPLATE, File.join(@app.root_path, 'config', 'webpack', 'development.js')
|
51
|
+
template PRODUCTION_WEBPACK_TEMPLATE, File.join(@app.root_path, 'config', 'webpack', 'production.js')
|
52
|
+
end
|
53
|
+
|
54
|
+
def enable_react
|
55
|
+
@packages.push(
|
56
|
+
'babel-preset-react',
|
57
|
+
'react',
|
58
|
+
'react-dom',
|
59
|
+
'react-hot-loader'
|
60
|
+
)
|
61
|
+
@presets = ['env', 'react']
|
62
|
+
@loaders.push({
|
63
|
+
test: /\.(js|jsx)$/,
|
64
|
+
use: 'babel-loader'
|
65
|
+
})
|
12
66
|
end
|
13
67
|
|
14
68
|
# Add to CLI
|
15
69
|
Base.register( self, 'webpack', 'webpack [options]', 'Install webpack to middleman')
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
def default_packages
|
74
|
+
[
|
75
|
+
'webpack',
|
76
|
+
'webpack-cli',
|
77
|
+
'webpack-merge',
|
78
|
+
'webpack-dev-server',
|
79
|
+
'babel-loader',
|
80
|
+
'babel-core',
|
81
|
+
'babel-preset-env',
|
82
|
+
'compression-webpack-plugin'
|
83
|
+
]
|
84
|
+
end
|
16
85
|
end
|
17
86
|
end
|
18
87
|
end
|
@@ -1,20 +1,23 @@
|
|
1
1
|
# Require core library
|
2
2
|
require 'middleman-core'
|
3
3
|
|
4
|
+
require 'middleman-webpacked/command_runner'
|
5
|
+
require 'middleman-webpacked/server'
|
6
|
+
require 'middleman-webpacked/build'
|
7
|
+
|
4
8
|
# Extension namespace
|
5
9
|
module Middleman
|
6
10
|
class WebpackedExtension < ::Middleman::Extension
|
7
|
-
|
8
|
-
option :entry, {bundle: 'index.js'}, 'The entry points(s) of the compilation'
|
11
|
+
include MiddlemanWebpacked
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
option :source, '.webpack-cache', 'The webpack cache path'
|
14
|
+
option :entry, {bundle: 'index.js'}, 'The entry points(s) of the compilation'
|
12
15
|
|
13
16
|
def initialize(app, options_hash={}, &block)
|
14
17
|
super
|
15
18
|
|
16
|
-
fail 'Webpack Dev Server not found' unless
|
17
|
-
fail 'Webpack not found' unless
|
19
|
+
fail 'Webpack Dev Server not found' unless Server.satisfy?
|
20
|
+
fail 'Webpack not found' unless Build.satisfy?
|
18
21
|
end
|
19
22
|
|
20
23
|
def after_configuration
|
@@ -30,19 +33,11 @@ module Middleman
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def command
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
"--output-public-path /#{app.config[:js_dir]} "
|
39
|
-
end
|
40
|
-
|
41
|
-
def build_command
|
42
|
-
"#{WEBPACK_BIN} --mode production " \
|
43
|
-
'--module-bind js=babel-loader ' \
|
44
|
-
"#{options.entry.map { |name, path| "--entry #{name}=./src/#{path}" }.join(' ')} " \
|
45
|
-
"--bail -p --output-path #{options.source}/#{app.config[:js_dir]}"
|
36
|
+
if app.build?
|
37
|
+
Build
|
38
|
+
else
|
39
|
+
Server
|
40
|
+
end.new(app, options).command
|
46
41
|
end
|
47
42
|
|
48
43
|
def after_build
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module MiddlemanWebpacked
|
2
|
+
class Server < CommandRunner
|
3
|
+
bin 'node_modules/.bin/webpack-dev-server'
|
4
|
+
mode :development
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@arguments.push(
|
8
|
+
'--hot',
|
9
|
+
'--progress',
|
10
|
+
'--color',
|
11
|
+
'--inline',
|
12
|
+
'--content-base source',
|
13
|
+
"--output-public-path http://localhost:8080/#{app.config[:js_dir]}",
|
14
|
+
"--config #{app.root_path}/config/webpack/development.js"
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
const merge = require('webpack-merge')
|
2
|
+
const sharedConfig = require('./shared.js')
|
3
|
+
|
4
|
+
module.exports = merge(sharedConfig, {
|
5
|
+
devServer: {
|
6
|
+
headers: {
|
7
|
+
'Access-Control-Allow-Origin': '*',
|
8
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
9
|
+
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
|
10
|
+
},
|
11
|
+
},
|
12
|
+
})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-webpacked
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aotokitsuruya
|
@@ -37,8 +37,15 @@ files:
|
|
37
37
|
- Rakefile
|
38
38
|
- features/support/env.rb
|
39
39
|
- lib/middleman-webpacked.rb
|
40
|
+
- lib/middleman-webpacked/build.rb
|
41
|
+
- lib/middleman-webpacked/command_runner.rb
|
40
42
|
- lib/middleman-webpacked/commands/webpack.rb
|
41
43
|
- lib/middleman-webpacked/extension.rb
|
44
|
+
- lib/middleman-webpacked/server.rb
|
45
|
+
- lib/middleman-webpacked/template/babelrc.tt
|
46
|
+
- lib/middleman-webpacked/template/dev.webpack.tt
|
47
|
+
- lib/middleman-webpacked/template/prod.webpack.tt
|
48
|
+
- lib/middleman-webpacked/template/shared.webpack.tt
|
42
49
|
- lib/middleman-webpacked/version.rb
|
43
50
|
- middleman-webpacked.gemspec
|
44
51
|
homepage: https://github.com/elct9620/middleman-webpacked
|