@epublishing/grunt-epublishing 0.3.1 → 0.3.3
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.
- package/lib/configure-sass.js +2 -9
- package/lib/configure-webpack.js +96 -67
- package/lib/init-jade-config.js +1 -2
- package/package.json +9 -4
- package/tasks/jade.js +8 -0
package/lib/configure-sass.js
CHANGED
|
@@ -4,20 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
const sass = require('node-sass');
|
|
7
|
+
const sass = require('sass');
|
|
9
8
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
10
9
|
|
|
11
10
|
module.exports = function configureSass(config) {
|
|
12
11
|
|
|
13
12
|
config.sass.options.functions = {
|
|
14
|
-
'epub-
|
|
15
|
-
if (_.includes([ 'local', 'development' ], NODE_ENV)) {
|
|
16
|
-
return sass.types.Boolean.TRUE;
|
|
17
|
-
}
|
|
18
|
-
return sass.types.Boolean.FALSE;
|
|
19
|
-
},
|
|
20
|
-
'epub-node-env()': () => new sass.types.String(NODE_ENV),
|
|
13
|
+
'epub-node-env()': () => new sass.String(NODE_ENV),
|
|
21
14
|
};
|
|
22
15
|
|
|
23
16
|
return config;
|
package/lib/configure-webpack.js
CHANGED
|
@@ -3,25 +3,26 @@
|
|
|
3
3
|
* targets, including loaders and output plugins.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const os
|
|
9
|
-
const fs
|
|
10
|
-
const path
|
|
11
|
-
const webpack
|
|
12
|
-
const BundleAnalyzerPlugin =
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const os = require("os");
|
|
9
|
+
const fs = require("fs");
|
|
10
|
+
const path = require("path");
|
|
11
|
+
const webpack = require("webpack");
|
|
12
|
+
const BundleAnalyzerPlugin =
|
|
13
|
+
require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
|
|
14
|
+
const CompressionPlugin = require("compression-webpack-plugin");
|
|
15
|
+
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
|
|
16
|
+
const lodashDir = path.dirname(require.resolve("lodash"));
|
|
17
|
+
const moduleDir = path.dirname(lodashDir);
|
|
17
18
|
|
|
18
19
|
module.exports = function configureWebpack(grunt, config) {
|
|
19
|
-
const { NODE_ENV =
|
|
20
|
-
const watch
|
|
21
|
-
const verbose
|
|
22
|
-
const noMinify = !!grunt.option(
|
|
23
|
-
const analyze
|
|
24
|
-
const lint
|
|
20
|
+
const { NODE_ENV = "development" } = process.env;
|
|
21
|
+
const watch = !!grunt.option("watch");
|
|
22
|
+
const verbose = !!grunt.option("verbose");
|
|
23
|
+
const noMinify = !!grunt.option("no-minify");
|
|
24
|
+
const analyze = !!grunt.option("analyze");
|
|
25
|
+
const lint = NODE_ENV === "test" || !!grunt.option("lint");
|
|
25
26
|
|
|
26
27
|
for (const target in config.webpack) {
|
|
27
28
|
const targetConfig = config.webpack[target];
|
|
@@ -42,45 +43,67 @@ module.exports = function configureWebpack(grunt, config) {
|
|
|
42
43
|
// This prevents Webpack from loading every single locale definition file that Moment.js provides.
|
|
43
44
|
// 99% of the time we only care about formatting dates in US English, so we have no need for i.e.
|
|
44
45
|
// the preferred date formats of Esperanto-speaking residents of Papua New Guinea. American cultural hedgemony FTW!
|
|
45
|
-
const momentLocales = new webpack.ContextReplacementPlugin(
|
|
46
|
+
const momentLocales = new webpack.ContextReplacementPlugin(
|
|
47
|
+
/moment[/\\]locale$/,
|
|
48
|
+
/en/
|
|
49
|
+
);
|
|
46
50
|
|
|
47
|
-
let plugins = [
|
|
51
|
+
let plugins = [environmentVars, momentLocales];
|
|
48
52
|
|
|
49
53
|
if (!config.babelLoader) {
|
|
50
|
-
config.babelLoader = {
|
|
54
|
+
config.babelLoader = {
|
|
55
|
+
exceptions: [],
|
|
56
|
+
exclude: /(node_modules|bower_components)/,
|
|
57
|
+
};
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
const babelExclude = config.babelLoader.exclude;
|
|
54
|
-
const babelExceptions = config.babelLoader.exceptions.map(
|
|
61
|
+
const babelExceptions = config.babelLoader.exceptions.map(
|
|
62
|
+
(mod) => new RegExp(`node_modules/${mod}/(.+)\\.js$`)
|
|
63
|
+
);
|
|
55
64
|
|
|
56
|
-
targetConfig.watch
|
|
57
|
-
targetConfig.keepalive
|
|
58
|
-
targetConfig.stats.modules
|
|
59
|
-
targetConfig.stats.reasons
|
|
60
|
-
targetConfig.profile
|
|
65
|
+
targetConfig.watch = watch;
|
|
66
|
+
targetConfig.keepalive = watch || analyze;
|
|
67
|
+
targetConfig.stats.modules = verbose;
|
|
68
|
+
targetConfig.stats.reasons = verbose;
|
|
69
|
+
targetConfig.profile = analyze;
|
|
61
70
|
|
|
62
71
|
// Tell babel-plugin-lodash where to find modularized Lo-Dash functions:
|
|
63
72
|
targetConfig.resolve.alias.lodash = lodashDir;
|
|
64
73
|
|
|
65
74
|
const babelOptions = {
|
|
66
75
|
presets: [
|
|
67
|
-
[
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
[
|
|
77
|
+
require.resolve("@epublishing/babel-preset-epublishing"),
|
|
78
|
+
{
|
|
79
|
+
lodash: { cwd: moduleDir },
|
|
80
|
+
env: {
|
|
81
|
+
modules: false,
|
|
82
|
+
},
|
|
83
|
+
minify: false,
|
|
71
84
|
},
|
|
72
|
-
|
|
73
|
-
}],
|
|
85
|
+
],
|
|
74
86
|
],
|
|
75
|
-
|
|
87
|
+
plugins: [
|
|
88
|
+
[
|
|
89
|
+
require.resolve("babel-plugin-transform-react-jsx"),
|
|
90
|
+
{
|
|
91
|
+
pragma: "h",
|
|
92
|
+
// pragmaFrag: "Fragment",
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
],
|
|
96
|
+
};
|
|
76
97
|
|
|
77
98
|
const rules = [
|
|
78
99
|
{
|
|
79
100
|
test: /\.jsx?$/,
|
|
80
|
-
loader:
|
|
101
|
+
loader: "babel-loader",
|
|
81
102
|
exclude: (input) => {
|
|
82
103
|
// Check whether the asset has a matching exclusion exception pattern and allow it to transpile if it does:
|
|
83
|
-
const isException = babelExceptions.some((pattern) =>
|
|
104
|
+
const isException = babelExceptions.some((pattern) =>
|
|
105
|
+
pattern.test(input)
|
|
106
|
+
);
|
|
84
107
|
if (isException) return !isException;
|
|
85
108
|
|
|
86
109
|
// Test asset against the default exclusion pattern and return result:
|
|
@@ -93,44 +116,43 @@ module.exports = function configureWebpack(grunt, config) {
|
|
|
93
116
|
exclude: /node_modules/,
|
|
94
117
|
use: [
|
|
95
118
|
{
|
|
96
|
-
loader:
|
|
119
|
+
loader: "babel-loader",
|
|
97
120
|
options: babelOptions,
|
|
98
121
|
},
|
|
99
122
|
{
|
|
100
|
-
loader:
|
|
123
|
+
loader: "ts-loader",
|
|
101
124
|
},
|
|
102
125
|
],
|
|
103
126
|
},
|
|
104
127
|
{
|
|
105
128
|
test: /\.css$/,
|
|
106
|
-
use: [
|
|
107
|
-
'style-loader',
|
|
108
|
-
'css-loader',
|
|
109
|
-
],
|
|
129
|
+
use: ["style-loader", "css-loader"],
|
|
110
130
|
},
|
|
111
131
|
{
|
|
112
|
-
test: [
|
|
113
|
-
loader:
|
|
132
|
+
test: [/\.svg$/, /\.jpe?g$/, /\.gif$/, /\.png$/],
|
|
133
|
+
loader: "file-loader",
|
|
114
134
|
},
|
|
115
135
|
];
|
|
116
136
|
|
|
117
137
|
if (lint) {
|
|
118
|
-
const localEslintConfig = path.join(process.cwd(),
|
|
119
|
-
const globalEslintConfig = path.resolve(__dirname,
|
|
120
|
-
const eslintConfig = fs.existsSync(localEslintConfig)
|
|
138
|
+
const localEslintConfig = path.join(process.cwd(), ".eslintrc");
|
|
139
|
+
const globalEslintConfig = path.resolve(__dirname, "../.eslintrc");
|
|
140
|
+
const eslintConfig = fs.existsSync(localEslintConfig)
|
|
141
|
+
? localEslintConfig
|
|
142
|
+
: globalEslintConfig;
|
|
121
143
|
|
|
122
144
|
rules.push({
|
|
123
|
-
enforce:
|
|
145
|
+
enforce: "pre",
|
|
124
146
|
test: /\.js$/,
|
|
125
147
|
exclude: /(node_modules|bower_components|public|vendor)/,
|
|
126
|
-
loader:
|
|
148
|
+
loader: "eslint-loader",
|
|
127
149
|
options: {
|
|
128
150
|
configFile: eslintConfig,
|
|
129
|
-
formatter: require(
|
|
151
|
+
formatter: require("eslint-friendly-formatter"),
|
|
130
152
|
failOnError: true,
|
|
131
153
|
outputReport: {
|
|
132
|
-
filePath:
|
|
133
|
-
formatter: require(
|
|
154
|
+
filePath: "eslint.xml",
|
|
155
|
+
formatter: require("eslint/lib/formatters/junit"),
|
|
134
156
|
},
|
|
135
157
|
},
|
|
136
158
|
});
|
|
@@ -140,14 +162,14 @@ module.exports = function configureWebpack(grunt, config) {
|
|
|
140
162
|
|
|
141
163
|
if (analyze) {
|
|
142
164
|
const bundleAnalyzer = new BundleAnalyzerPlugin({
|
|
143
|
-
analyzerMode:
|
|
144
|
-
analyzerHost:
|
|
145
|
-
analyzerPort:
|
|
146
|
-
reportFilename:
|
|
147
|
-
defaultSizes:
|
|
165
|
+
analyzerMode: "server",
|
|
166
|
+
analyzerHost: "127.0.0.1",
|
|
167
|
+
analyzerPort: "8888",
|
|
168
|
+
reportFilename: "webpack-analysis.html",
|
|
169
|
+
defaultSizes: "parsed",
|
|
148
170
|
openAnalyzer: true,
|
|
149
171
|
generateStatsFile: true,
|
|
150
|
-
statsFilename:
|
|
172
|
+
statsFilename: "webpack.stats.json",
|
|
151
173
|
statsOptions: { chunkModules: true },
|
|
152
174
|
});
|
|
153
175
|
plugins.push(bundleAnalyzer);
|
|
@@ -162,17 +184,21 @@ module.exports = function configureWebpack(grunt, config) {
|
|
|
162
184
|
const { uglifyConfig = {} } = targetConfig;
|
|
163
185
|
delete targetConfig.uglifyConfig;
|
|
164
186
|
|
|
165
|
-
plugins.push(
|
|
187
|
+
plugins.push(
|
|
188
|
+
new UglifyJsPlugin(Object.assign({}, uglifyDefaults, uglifyConfig))
|
|
189
|
+
);
|
|
166
190
|
}
|
|
167
191
|
|
|
168
|
-
if (NODE_ENV ===
|
|
169
|
-
plugins.push(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
192
|
+
if (NODE_ENV === "production") {
|
|
193
|
+
plugins.push(
|
|
194
|
+
new CompressionPlugin({
|
|
195
|
+
asset: "[path].gz",
|
|
196
|
+
algorithm: "gzip",
|
|
197
|
+
test: /\.js$/,
|
|
198
|
+
threshold: 10240,
|
|
199
|
+
minRatio: 0.8,
|
|
200
|
+
})
|
|
201
|
+
);
|
|
176
202
|
}
|
|
177
203
|
|
|
178
204
|
if (Array.isArray(targetConfig.appendPlugins)) {
|
|
@@ -182,7 +208,10 @@ module.exports = function configureWebpack(grunt, config) {
|
|
|
182
208
|
|
|
183
209
|
targetConfig.plugins = plugins;
|
|
184
210
|
|
|
185
|
-
if (
|
|
211
|
+
if (
|
|
212
|
+
targetConfig.customize &&
|
|
213
|
+
typeof targetConfig.customize === "function"
|
|
214
|
+
) {
|
|
186
215
|
config.webpack[target] = targetConfig.customize(targetConfig, webpack);
|
|
187
216
|
delete config.webpack[target].customize;
|
|
188
217
|
}
|
package/lib/init-jade-config.js
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
const _ = require('lodash');
|
|
11
10
|
const fs = require('fs');
|
|
12
11
|
const prettyjson = require('prettyjson');
|
|
13
12
|
const mergeConfigs = require('./merge-configs');
|
|
@@ -31,7 +30,7 @@ module.exports = function initJadeConfig(grunt, jadePath, jadeChildPath, jadeChi
|
|
|
31
30
|
baseConfig = mergeConfigs(baseConfig, jadePath);
|
|
32
31
|
|
|
33
32
|
// Loop through all detected engine gem paths and merge their Grunt configurations into baseConfig
|
|
34
|
-
for (const childPath of
|
|
33
|
+
for (const childPath of Object.values(jadeChildPaths)) {
|
|
35
34
|
baseConfig = mergeConfigs(baseConfig, childPath);
|
|
36
35
|
}
|
|
37
36
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epublishing/grunt-epublishing",
|
|
3
3
|
"description": "Automated front-end tasks for ePublishing Jade and client sites.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.3",
|
|
5
5
|
"homepage": "https://www.epublishing.com",
|
|
6
6
|
"contributors": [
|
|
7
7
|
{
|
|
@@ -11,21 +11,26 @@
|
|
|
11
11
|
{
|
|
12
12
|
"name": "Mike Green",
|
|
13
13
|
"email": "mgreen@epublishing.com"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "Michael Hedges",
|
|
17
|
+
"email": "mhedges@epublishing.com"
|
|
14
18
|
}
|
|
15
19
|
],
|
|
16
20
|
"repository": "bitbucket:epub_dev/grunt-epublishing",
|
|
17
21
|
"license": "MIT",
|
|
18
22
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
23
|
+
"node": ">= 12.22.12"
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|
|
22
|
-
"@epublishing/babel-preset-epublishing": "^0.1.
|
|
26
|
+
"@epublishing/babel-preset-epublishing": "^0.1.8",
|
|
23
27
|
"@epublishing/get-gem-paths": "^0.1.1",
|
|
24
28
|
"@epublishing/grunt-install-eslint": "^0.1.1",
|
|
25
29
|
"@epublishing/jade-resolver": "^0.1.2",
|
|
26
30
|
"async": "^2.6.1",
|
|
27
31
|
"babel-loader": "^7.1.5",
|
|
28
32
|
"babel-minify-webpack-plugin": "^0.3.0",
|
|
33
|
+
"babel-plugin-transform-react-jsx": "^6.24.1",
|
|
29
34
|
"bourbon": "^4.2.7",
|
|
30
35
|
"breakpoint-sass": "^2.7.0",
|
|
31
36
|
"chalk": "^2.4.1",
|
|
@@ -64,10 +69,10 @@
|
|
|
64
69
|
"jit-grunt": "^0.10.0",
|
|
65
70
|
"listr": "^0.14.1",
|
|
66
71
|
"lodash": "^4.17.10",
|
|
67
|
-
"node-sass": "^6.0.1",
|
|
68
72
|
"postcss-css-variables": "^0.9.0",
|
|
69
73
|
"prettyjson": "^1.2.1",
|
|
70
74
|
"read-pkg": "^4.0.1",
|
|
75
|
+
"sass": "^1.71.1",
|
|
71
76
|
"style-loader": "^0.20.2",
|
|
72
77
|
"susy": "^2.2.14",
|
|
73
78
|
"time-grunt": "^1.4.0",
|
package/tasks/jade.js
CHANGED
|
@@ -14,11 +14,19 @@ const initJadeConfig = require('../lib/init-jade-config');
|
|
|
14
14
|
module.exports = function(grunt) {
|
|
15
15
|
grunt.option('siteRoot', process.cwd())
|
|
16
16
|
|
|
17
|
+
console.log('~~~~~~~~~~~~~~~~~~~~')
|
|
18
|
+
console.log('~~~~~~~DEBUG~~~~~~~~')
|
|
19
|
+
console.log('~~~~~~~~~~~~~~~~~~~~')
|
|
20
|
+
|
|
21
|
+
|
|
17
22
|
if (!grunt.option('no-time')) timeGrunt(grunt);
|
|
23
|
+
|
|
18
24
|
jitGrunt(grunt, {
|
|
19
25
|
'install-eslint': '@epublishing/grunt-install-eslint',
|
|
20
26
|
});
|
|
21
27
|
|
|
28
|
+
|
|
29
|
+
|
|
22
30
|
/**
|
|
23
31
|
* This registers a grunt task which shells out and uses bundler to
|
|
24
32
|
* determine the paths to the jade gem and any jade child engine gem
|