Skip to content

Commit 31b7214

Browse files
committed
README updated
1 parent 0aeadef commit 31b7214

File tree

3 files changed

+87
-31
lines changed

3 files changed

+87
-31
lines changed

README.md

Lines changed: 66 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ COMPRESS_PRECOMPILERS = (
4545
{% endcompress %}
4646
```
4747

48-
```scss
49-
/* base/static/base/variables.scss */
50-
51-
$title-size: 30px;
52-
```
53-
5448
```scss
5549
/* app/static/app/layout.scss */
5650

@@ -61,9 +55,15 @@ $title-size: 30px;
6155
}
6256
```
6357

58+
```scss
59+
/* base/static/base/variables.scss */
60+
61+
$title-size: 30px;
62+
```
63+
6464
#### Requisites
6565

66-
You need `node-sass`, `postcss` and `autoprefixer` to be installed. Quick install:
66+
You need `node-sass`, `postcss-cli` and `autoprefixer` to be installed. Quick install:
6767

6868
```sh
6969
npm install -g node-sass postcss-cli autoprefixer
@@ -85,7 +85,6 @@ ES6 → (
8585

8686
It also enables Django static imports in ES6, see the example below.
8787

88-
8988
#### Usage
9089

9190
```py
@@ -106,6 +105,15 @@ COMPRESS_PRECOMPILERS = (
106105
{% endcompress %}
107106
```
108107

108+
```js
109+
// app/static/app/scripts.js
110+
111+
import Framework from 'base/framework';
112+
113+
new Framework;
114+
new Framework('1.0.1');
115+
```
116+
109117
```js
110118
// base/static/base/framework.js
111119

@@ -118,19 +126,61 @@ export default class {
118126
}
119127
```
120128

121-
```js
122-
// app/static/app/scripts.js
129+
#### Requisites
123130

124-
import Framework from 'base/framework';
131+
You need `browserify`, `babelify` and `babel-preset-es2015` to be installed. Quick install:
125132

126-
new Framework;
127-
new Framework('1.0.1');
133+
```sh
134+
npm install -g browserify babelify babel-preset-es2015
128135
```
129136

130-
#### Requisites
137+
## Django settings
131138

132-
You need `browserify`, `babelify` and `babel-preset-es2015` to be installed. Quick install:
139+
### COMPRESS_NODE_MODULES
140+
141+
Path to `node_modules` where `browserify`, `babelify`, `autoprefixer`, etc, are installed.
142+
143+
Default: `/usr/lib/node_modules`
144+
145+
### COMPRESS_SCSS_COMPILER_CMD
146+
147+
Command that will be executed to transform SCSS into CSS code.
148+
149+
Default:
133150

134151
```sh
135-
npm install -g browserify babelify babel-preset-es2015
152+
node-sass --output-style expanded {paths} "{infile}" "{outfile}" &&
153+
postcss --use "{node_modules}/autoprefixer" --autoprefixer.browsers "{autoprefixer_browsers}" -r "{outfile}"'
154+
```
155+
156+
Placeholders:
157+
- `{infile}` - input file path
158+
- `{outfile}` - output file path
159+
- `{paths}` - specially for `node-sass`, include all Django app static folders:
160+
`--include-path=/path/to/app-1/static/ --include-path=/path/to/app-2/static/ ...`
161+
- `{node_modules}` - see `COMPRESS_NODE_MODULES` setting
162+
- `{autoprefixer_browsers}` - see `COMPRESS_AUTOPREFIXER_BROWSERS` setting
163+
164+
### COMPRESS_AUTOPREFIXER_BROWSERS
165+
166+
Browser versions config for Autoprefixer.
167+
168+
Default: `ie >= 9, > 5%`
169+
170+
### COMPRESS_ES6_COMPILER_CMD
171+
172+
Command that will be executed to transform ES6 into ES5 code.
173+
174+
Default:
175+
176+
```sh
177+
export NODE_PATH="{paths}" && browserify "{infile}" -o "{outfile}" --no-bundle-external --node
178+
-t [ "{node_modules}/babelify" --presets="{node_modules}/babel-preset-es2015" ]
136179
```
180+
181+
Placeholders:
182+
- `{infile}` - input file path
183+
- `{outfile}` - output file path
184+
- `{paths}` - specially for `browserify`, include all Django app static folders:
185+
`/path/to/app-1/static/:/path/to/app-2/static/:...` (like `PATH` variable)
186+
- `{node_modules}` - see `COMPRESS_NODE_MODULES` setting

compressor_toolkit/apps.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,24 @@
55
class CompressorToolkitConfig(AppConfig):
66
name = 'compressor_toolkit'
77

8+
# Path to 'node_modules' where browserify, babelify, autoprefixer, etc, are installed
9+
NODE_MODULES = getattr(settings, 'COMPRESS_NODE_MODULES', None) or '/usr/lib/node_modules'
10+
811
# Custom SCSS transpiler command
9-
SCSS_COMPILER_CMD = getattr(settings, 'COMPRESS_SCSS_COMPILER_CMD', None)
12+
SCSS_COMPILER_CMD = getattr(settings, 'COMPRESS_SCSS_COMPILER_CMD', None) or (
13+
'node-sass --output-style expanded {paths} "{infile}" "{outfile}" && '
14+
'postcss --use "{node_modules}/autoprefixer" '
15+
'--autoprefixer.browsers "{autoprefixer_browsers}" -r "{outfile}"'
16+
)
1017

11-
# Custom ES6 transpiler command
12-
ES6_COMPILER_CMD = getattr(settings, 'COMPRESS_ES6_COMPILER_CMD', None)
18+
# Browser versions config for Autoprefixer
19+
AUTOPREFIXER_BROWSERS = getattr(settings, 'COMPRESS_AUTOPREFIXER_BROWSERS', None) or (
20+
'ie >= 9, > 5%'
21+
)
1322

14-
# Path to 'node_modules' where browserify, babelify, autoprefixer, etc, are installed
15-
NODE_MODULES = getattr(settings, 'COMPRESS_NODE_MODULES', None) or '/usr/lib/node_modules'
23+
# Custom ES6 transpiler command
24+
ES6_COMPILER_CMD = getattr(settings, 'COMPRESS_ES6_COMPILER_CMD', None) or (
25+
'export NODE_PATH="{paths}" && '
26+
'browserify "{infile}" -o "{outfile}" --no-bundle-external --node '
27+
'-t [ "{node_modules}/babelify" --presets="{node_modules}/babel-preset-es2015" ]'
28+
)

compressor_toolkit/precompilers.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,11 @@ class SCSSCompiler(BaseCompiler):
7575
font-size: $title-font-size;
7676
}
7777
"""
78-
command = app_config.SCSS_COMPILER_CMD or (
79-
'node-sass --output-style expanded {paths} {infile} {outfile} && '
80-
'postcss --use {node_modules}/autoprefixer '
81-
'--autoprefixer.browsers "ie >= 9, > 5%" -r {outfile}'
82-
)
78+
command = app_config.SCSS_COMPILER_CMD
8379
options = (
8480
('paths', ' '.join(['--include-path {}'.format(s) for s in get_all_static()])),
8581
('node_modules', app_config.NODE_MODULES),
82+
('autoprefixer_browsers', app_config.AUTOPREFIXER_BROWSERS),
8683
)
8784
infile_ext = '.scss'
8885

@@ -104,11 +101,7 @@ class ES6Compiler(BaseCompiler):
104101
105102
controller.registerPages(login, signup);
106103
"""
107-
command = app_config.ES6_COMPILER_CMD or (
108-
'export NODE_PATH={paths} && '
109-
'browserify "{infile}" -o "{outfile}" --no-bundle-external --node '
110-
'-t [ {node_modules}/babelify --presets={node_modules}/babel-preset-es2015 ]'
111-
)
104+
command = app_config.ES6_COMPILER_CMD
112105
options = (
113106
('paths', os.pathsep.join(get_all_static())),
114107
('node_modules', app_config.NODE_MODULES)

0 commit comments

Comments
 (0)