middleman-webpacker 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +3 -0
- data/LICENSE.md +18 -0
- data/README.md +68 -0
- data/Rakefile +14 -0
- data/features/support/env.rb +5 -0
- data/lib/middleman-webpacker/extension.rb +39 -0
- data/lib/middleman-webpacker/file_loader.rb +25 -0
- data/lib/middleman-webpacker/helpers.rb +29 -0
- data/lib/middleman-webpacker/manifest.rb +26 -0
- data/lib/middleman-webpacker/version.rb +3 -0
- data/lib/middleman-webpacker.rb +6 -0
- data/middleman-webpacker.gemspec +27 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: adfa59b40717784472840824fa064fbc97d2a0ac
|
4
|
+
data.tar.gz: 592239fd7fe623e02f8454741d9fddf7df9fe3bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a45408ba7a24ae2037c972f6097c8298bca8a6517cce153e809e2a072da7a32e31f22704711c9dc8cbc7d7b2851aa5fc33c21a19c14b475db55f7d072963536
|
7
|
+
data.tar.gz: f83fef594378fd4dd232095f285cf570346a6f0e88ebacef14045532dfe1c101c09ebd56f07e68e1d0f50fcc7672baba6e0190b6be7da57aa8c60bc3a9b30948
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2010-2017 Thomas Reynolds
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Middleman Webpacker Extension
|
2
|
+
|
3
|
+
This extensions allows to use Webpack in [Middleman](https://middlemanapp.com/) (>= 4) applications through the external pipeline feature introduced in Middleman 4.
|
4
|
+
|
5
|
+
It's heavily inspired in the Webpacker gem for Rails.
|
6
|
+
|
7
|
+
## Dependencies
|
8
|
+
|
9
|
+
* Middleman >= 4
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
If you're just getting started, install the middleman gem and generate a new project:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install middleman
|
17
|
+
middleman init MY_PROJECT
|
18
|
+
```
|
19
|
+
|
20
|
+
If you already have a Middleman project: Add this to the Gemfile and run `bundle install`
|
21
|
+
|
22
|
+
```
|
23
|
+
gem 'middleman-webpacker'
|
24
|
+
```
|
25
|
+
|
26
|
+
## Configuration
|
27
|
+
|
28
|
+
```
|
29
|
+
activate :webpack
|
30
|
+
```
|
31
|
+
|
32
|
+
Then you need to provide your Webpack configuration inside the `config` folder. The extension requires to have 2 configuration files:
|
33
|
+
* `development.js` used during development.
|
34
|
+
* `production.js` used when building the site.
|
35
|
+
|
36
|
+
The extension provides the following configuration options:
|
37
|
+
|
38
|
+
`dist_path` (default: 'dist')
|
39
|
+
|
40
|
+
Output directory configured in Webpack.
|
41
|
+
|
42
|
+
`stylesheets_base_path` (default: '')
|
43
|
+
|
44
|
+
Base path where stylesheets will be placed inside dist_path.
|
45
|
+
|
46
|
+
`javascripts_base_path` (default: '')
|
47
|
+
|
48
|
+
Base path where javascripts will be placed inside dist_path.
|
49
|
+
|
50
|
+
`images_base_path` (default: 'img/')
|
51
|
+
|
52
|
+
Base path where images will be placed inside dist_path.
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
When activating the extension, Webpack will be used with the provided configuration. The extension is configured to have Webpack take care of all assets: Javascript, stylesheets, images and fonts.
|
57
|
+
|
58
|
+
This means that all of these assets need to be covered in your Webpack configuration.
|
59
|
+
|
60
|
+
In order to be able to use the assets compiled by Webpack from the HTML you can use the following helpers:
|
61
|
+
* `javascript_pack_tag` which replaces `javascript_include_tag`
|
62
|
+
* `stylesheet_pack_tag` which replaces `stylesheet_link_tag`
|
63
|
+
* `image_pack_tag` which replaces `image_tag`
|
64
|
+
* `asset_pack_path` which replaces `asset_path`
|
65
|
+
|
66
|
+
## TODO
|
67
|
+
|
68
|
+
1. Provide a base Webpack configuration (a la webpacker)
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
t.cucumber_opts = '--color --tags ~@wip --strict'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/clean'
|
11
|
+
|
12
|
+
task test: ['cucumber']
|
13
|
+
|
14
|
+
task default: :test
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'middleman-core'
|
2
|
+
require 'middleman-webpacker/helpers'
|
3
|
+
|
4
|
+
module MiddlemanWebpacker
|
5
|
+
class Extension < ::Middleman::Extension
|
6
|
+
|
7
|
+
DEVELOPMENT_WEBPACK_CMD = './node_modules/webpack/bin/webpack.js ' \
|
8
|
+
'--watch -d --progress --color --config config/webpack/development.js'
|
9
|
+
PRODUCTION_WEBPACK_CMD = 'NODE_ENV=production ./node_modules/webpack/bin/webpack.js ' \
|
10
|
+
'--bail -p --config config/webpack/production.js'
|
11
|
+
|
12
|
+
option :dist_path, 'dist', 'Output directory configured in Webpack'
|
13
|
+
option :stylesheets_base_path, '', 'Base path where stylesheets will be placed inside dist_path'
|
14
|
+
option :javascripts_base_path, '', 'Base path where javascripts will be placed inside dist_path'
|
15
|
+
option :images_base_path, 'img/', 'Base path where images will be placed inside dist_path'
|
16
|
+
|
17
|
+
self.defined_helpers = [MiddlemanWebpacker::Helpers]
|
18
|
+
|
19
|
+
def initialize(app, options_hash = {}, &block)
|
20
|
+
super
|
21
|
+
|
22
|
+
output_path = File.join(app.root, options.dist_path)
|
23
|
+
Manifest.file_path = File.join(output_path, 'manifest.json')
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_configuration
|
27
|
+
@app.ignore /stylesheets/
|
28
|
+
@app.ignore /javascripts/
|
29
|
+
@app.ignore /images/
|
30
|
+
@app.ignore /fonts/
|
31
|
+
|
32
|
+
@app.activate :external_pipeline,
|
33
|
+
name: :webpack,
|
34
|
+
command: @app.build? ? PRODUCTION_WEBPACK_CMD : DEVELOPMENT_WEBPACK_CMD,
|
35
|
+
source: options.dist_path,
|
36
|
+
latency: 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module MiddlemanWebpacker
|
2
|
+
class FileLoader
|
3
|
+
class NotFoundError < StandardError; end
|
4
|
+
class FileLoaderError < StandardError; end
|
5
|
+
|
6
|
+
class_attribute :instance
|
7
|
+
attr_accessor :data
|
8
|
+
|
9
|
+
def self.load(path = file_path)
|
10
|
+
self.instance = new(path)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def initialize(path)
|
16
|
+
@path = path
|
17
|
+
@data = load
|
18
|
+
end
|
19
|
+
|
20
|
+
def load
|
21
|
+
{}.freeze
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'middleman-webpacker/manifest'
|
2
|
+
|
3
|
+
module MiddlemanWebpacker
|
4
|
+
module Helpers
|
5
|
+
|
6
|
+
def stylesheet_pack_tag(name, **options)
|
7
|
+
stylesheet_link_tag(Manifest.lookup("#{extension_options.stylesheets_base_path}#{name}.css"), **options)
|
8
|
+
end
|
9
|
+
|
10
|
+
def javascript_pack_tag(name, **options)
|
11
|
+
javascript_include_tag(Manifest.lookup("#{extension_options.javascripts_base_path}#{name}.js"), **options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def image_pack_tag(name, **options)
|
15
|
+
image_tag(Manifest.lookup("#{extension_options.images_base_path}#{name}"), **options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def asset_pack_path(name, **options)
|
19
|
+
asset_path(Manifest.lookup(name), **options)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def extension_options
|
25
|
+
app.extensions[:webpack].options
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'middleman-webpacker/file_loader'
|
2
|
+
|
3
|
+
module MiddlemanWebpacker
|
4
|
+
class Manifest < FileLoader
|
5
|
+
|
6
|
+
class_attribute :file_path
|
7
|
+
|
8
|
+
def self.lookup(name)
|
9
|
+
load
|
10
|
+
|
11
|
+
unless instance
|
12
|
+
raise MiddlemanWebpacker::FileLoader::FileLoaderError.new('load must be called first')
|
13
|
+
end
|
14
|
+
|
15
|
+
instance.data[name.to_s] or raise(MiddlemanWebpacker::FileLoader::NotFoundError.new(
|
16
|
+
"Can't find #{name} in #{file_path}. Is webpack still compiling?"))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def load
|
22
|
+
return super unless File.exist?(@path)
|
23
|
+
JSON.parse(File.read(@path))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'middleman-webpacker/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'middleman-webpacker'
|
7
|
+
s.version = MiddlemanWebpacker::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = [ 'MarsBased' ]
|
10
|
+
s.email = [ 'hello@marsbased.com' ]
|
11
|
+
s.homepage = 'https://github.com/marsbased/middleman-webpacker'
|
12
|
+
s.summary = %q{ Extension to use Middleman with Webpack }
|
13
|
+
s.description = %q{ Extension to use Middleman with Webpack }
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files -z`.split("\0")
|
17
|
+
s.test_files = `git ls-files -z -- {spec,features,fixtures}/*`.split("\0")
|
18
|
+
s.require_paths = [ 'lib' ]
|
19
|
+
|
20
|
+
s.required_ruby_version = '>= 2.2.0'
|
21
|
+
|
22
|
+
s.add_runtime_dependency('middleman-core', ['>= 4.2.1'])
|
23
|
+
|
24
|
+
s.add_development_dependency('rake')
|
25
|
+
s.add_development_dependency('cucumber')
|
26
|
+
s.add_development_dependency('rspec')
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-webpacker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- MarsBased
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: " Extension to use Middleman with Webpack "
|
70
|
+
email:
|
71
|
+
- hello@marsbased.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.md
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- features/support/env.rb
|
82
|
+
- lib/middleman-webpacker.rb
|
83
|
+
- lib/middleman-webpacker/extension.rb
|
84
|
+
- lib/middleman-webpacker/file_loader.rb
|
85
|
+
- lib/middleman-webpacker/helpers.rb
|
86
|
+
- lib/middleman-webpacker/manifest.rb
|
87
|
+
- lib/middleman-webpacker/version.rb
|
88
|
+
- middleman-webpacker.gemspec
|
89
|
+
homepage: https://github.com/marsbased/middleman-webpacker
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.2.0
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.6.8
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Extension to use Middleman with Webpack
|
113
|
+
test_files:
|
114
|
+
- features/support/env.rb
|