generator-folklore 3.0.0-alpha.0 → 3.0.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/generators/babel/index.js +2 -4
- package/lib/generators/browserslist/templates/browserslistrc +8 -8
- package/lib/generators/build/index.js +45 -243
- package/lib/generators/docs/index.js +2 -6
- package/lib/generators/eslint/index.js +2 -10
- package/lib/generators/js/index.js +2 -6
- package/lib/generators/laravel-panneau/index.js +1 -3
- package/lib/generators/lerna-repository/index.js +1 -3
- package/lib/generators/npm-package/index.js +2 -6
- package/lib/generators/prettier/index.js +35 -0
- package/lib/generators/{eslint → prettier}/templates/prettierrc.json +0 -0
- package/lib/generators/react-package/index.js +2 -6
- package/lib/generators/storybook/index.js +1 -3
- package/lib/generators/stylelint/index.js +2 -4
- package/lib/generators/test/index.js +1 -3
- package/package.json +2 -2
- package/lib/generators/build/templates/config.js +0 -78
- package/lib/generators/build/templates/env.js +0 -90
- package/lib/generators/build/templates/paths.js +0 -92
- package/lib/generators/build/templates/polyfills.js +0 -25
- package/lib/generators/build/templates/postcss.config.js +0 -12
- package/lib/generators/build/templates/scripts/build.js +0 -158
- package/lib/generators/build/templates/scripts/imagemin.js +0 -59
- package/lib/generators/build/templates/scripts/modernizr.js +0 -22
- package/lib/generators/build/templates/scripts/server.js +0 -176
- package/lib/generators/build/templates/utils/getConfigValue.js +0 -5
- package/lib/generators/build/templates/utils/getLocalIdent.js +0 -11
- package/lib/generators/build/templates/webpack.config.dev.js +0 -394
- package/lib/generators/build/templates/webpack.config.prod.js +0 -571
- package/lib/generators/build/templates/webpackDevServer.config.js +0 -109
@@ -1,90 +0,0 @@
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies, global-require */
|
2
|
-
const fs = require('fs');
|
3
|
-
const path = require('path');
|
4
|
-
const paths = require('./paths');
|
5
|
-
|
6
|
-
// Make sure that including paths.js after env.js will read .env variables.
|
7
|
-
delete require.cache[require.resolve('./paths')];
|
8
|
-
|
9
|
-
const { NODE_ENV } = process.env;
|
10
|
-
if (!NODE_ENV) {
|
11
|
-
throw new Error('The NODE_ENV environment variable is required but was not specified.');
|
12
|
-
}
|
13
|
-
|
14
|
-
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
15
|
-
const dotenvFiles = [
|
16
|
-
`${paths.dotenv}.${NODE_ENV}.local`,
|
17
|
-
`${paths.dotenv}.${NODE_ENV}`,
|
18
|
-
// Don't include `.env.local` for `test` environment
|
19
|
-
// since normally you expect tests to produce the same
|
20
|
-
// results for everyone
|
21
|
-
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
|
22
|
-
paths.dotenv,
|
23
|
-
].filter(Boolean);
|
24
|
-
|
25
|
-
// Load environment variables from .env* files. Suppress warnings using silent
|
26
|
-
// if this file is missing. dotenv will never modify any environment variables
|
27
|
-
// that have already been set. Variable expansion is supported in .env files.
|
28
|
-
// https://github.com/motdotla/dotenv
|
29
|
-
// https://github.com/motdotla/dotenv-expand
|
30
|
-
dotenvFiles.forEach((dotenvFile) => {
|
31
|
-
if (fs.existsSync(dotenvFile)) {
|
32
|
-
require('dotenv-expand')(
|
33
|
-
require('dotenv').config({
|
34
|
-
path: dotenvFile,
|
35
|
-
}),
|
36
|
-
);
|
37
|
-
}
|
38
|
-
});
|
39
|
-
|
40
|
-
// We support resolving modules according to `NODE_PATH`.
|
41
|
-
// This lets you use absolute paths in imports inside large monorepos:
|
42
|
-
// https://github.com/facebook/create-react-app/issues/253.
|
43
|
-
// It works similar to `NODE_PATH` in Node itself:
|
44
|
-
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
|
45
|
-
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
46
|
-
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
47
|
-
// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
|
48
|
-
// We also resolve them to make sure all tools using them work consistently.
|
49
|
-
const appDirectory = fs.realpathSync(process.cwd());
|
50
|
-
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
51
|
-
.split(path.delimiter)
|
52
|
-
.filter(folder => folder && !path.isAbsolute(folder))
|
53
|
-
.map(folder => path.resolve(appDirectory, folder))
|
54
|
-
.join(path.delimiter);
|
55
|
-
|
56
|
-
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
57
|
-
// injected into the application via DefinePlugin in Webpack configuration.
|
58
|
-
const REACT_APP = /^REACT_APP_/i;
|
59
|
-
|
60
|
-
function getClientEnvironment(publicUrl) {
|
61
|
-
const raw = Object.keys(process.env)
|
62
|
-
.filter(key => REACT_APP.test(key))
|
63
|
-
.reduce(
|
64
|
-
(env, key) => ({
|
65
|
-
...env,
|
66
|
-
[key]: process.env[key],
|
67
|
-
}),
|
68
|
-
{
|
69
|
-
// Useful for determining whether we’re running in production mode.
|
70
|
-
// Most importantly, it switches React into the correct mode.
|
71
|
-
NODE_ENV: process.env.NODE_ENV || 'development',
|
72
|
-
// Useful for resolving the correct path to static assets in `public`.
|
73
|
-
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
74
|
-
// This should only be used as an escape hatch. Normally you would put
|
75
|
-
// images into the `src` and `import` them in code to get their paths.
|
76
|
-
PUBLIC_URL: publicUrl,
|
77
|
-
},
|
78
|
-
);
|
79
|
-
// Stringify all values so we can feed into Webpack DefinePlugin
|
80
|
-
const stringified = {
|
81
|
-
'process.env': Object.keys(raw).reduce((env, key) => ({
|
82
|
-
...env,
|
83
|
-
[key]: JSON.stringify(raw[key]),
|
84
|
-
}), {}),
|
85
|
-
};
|
86
|
-
|
87
|
-
return { raw, stringified };
|
88
|
-
}
|
89
|
-
|
90
|
-
module.exports = getClientEnvironment;
|
@@ -1,92 +0,0 @@
|
|
1
|
-
/* eslint-disable no-console, global-require */
|
2
|
-
/* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, import/order */
|
3
|
-
const path = require('path');
|
4
|
-
const fs = require('fs');
|
5
|
-
const url = require('url');
|
6
|
-
|
7
|
-
// Make sure any symlinks in the project folder are resolved:
|
8
|
-
// https://github.com/facebook/create-react-app/issues/637
|
9
|
-
const appDirectory = fs.realpathSync(process.cwd());
|
10
|
-
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
11
|
-
|
12
|
-
const envPublicUrl = process.env.PUBLIC_URL;
|
13
|
-
|
14
|
-
function ensureSlash(inputPath, needsSlash) {
|
15
|
-
const hasSlash = inputPath.endsWith('/');
|
16
|
-
if (hasSlash && !needsSlash) {
|
17
|
-
return inputPath.substr(0, inputPath.length - 1);
|
18
|
-
}
|
19
|
-
if (!hasSlash && needsSlash) {
|
20
|
-
return `${inputPath}/`;
|
21
|
-
}
|
22
|
-
return inputPath;
|
23
|
-
}
|
24
|
-
|
25
|
-
const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage;
|
26
|
-
|
27
|
-
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
28
|
-
// "public path" at which the app is served.
|
29
|
-
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
30
|
-
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
31
|
-
// We can't use a relative path in HTML because we don't want to load something
|
32
|
-
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
33
|
-
function getServedPath(appPackageJson) {
|
34
|
-
const publicUrl = getPublicUrl(appPackageJson);
|
35
|
-
const servedUrl = envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
36
|
-
return ensureSlash(servedUrl, true);
|
37
|
-
}
|
38
|
-
|
39
|
-
const moduleFileExtensions = [
|
40
|
-
'web.mjs',
|
41
|
-
'mjs',
|
42
|
-
'web.js',
|
43
|
-
'js',
|
44
|
-
'web.ts',
|
45
|
-
'ts',
|
46
|
-
'web.tsx',
|
47
|
-
'tsx',
|
48
|
-
'json',
|
49
|
-
'web.jsx',
|
50
|
-
'jsx',
|
51
|
-
];
|
52
|
-
|
53
|
-
// Resolve file paths in the same order as webpack
|
54
|
-
const resolveModule = (resolveFn, filePath) => {
|
55
|
-
if (fs.existsSync(resolveFn(filePath))) {
|
56
|
-
return resolveFn(filePath);
|
57
|
-
}
|
58
|
-
const extension = moduleFileExtensions.find(ext => fs.existsSync(resolveFn(`${filePath}.${ext}`)));
|
59
|
-
|
60
|
-
if (extension) {
|
61
|
-
return resolveFn(`${filePath}.${extension}`);
|
62
|
-
}
|
63
|
-
|
64
|
-
return resolveFn(`${filePath}.js`);
|
65
|
-
};
|
66
|
-
|
67
|
-
// config after eject: we're in ./config/
|
68
|
-
module.exports = {
|
69
|
-
dotenv: resolveApp('.env'),
|
70
|
-
appPath: resolveApp('.'),
|
71
|
-
appBuild: resolveApp('<%= buildPath %>'),
|
72
|
-
appPublic: resolveApp('<%= publicPath %>'),
|
73
|
-
appIndexJs: resolveModule(resolveApp, '<%= entryPath %>'),<% if (htmlPath !== null) { %>
|
74
|
-
appHtml: resolveApp('<%= htmlPath %>'),<% } %>
|
75
|
-
appPackageJson: resolveApp('package.json'),
|
76
|
-
appNodeModules: resolveApp('node_modules'),
|
77
|
-
appSrc: resolveApp('<%= srcPath %>'),
|
78
|
-
testsSetup: resolveModule(resolveApp, 'tests/setupTests'),
|
79
|
-
publicUrl: getPublicUrl(resolveApp('package.json')),
|
80
|
-
servedPath: getServedPath(resolveApp('package.json')),
|
81
|
-
copyPaths: [<% (copyPaths || []).forEach((dir) => { %>
|
82
|
-
resolveApp('<%= dir %>'),<% }) %>
|
83
|
-
],
|
84
|
-
emptyPaths: [<% (emptyPaths || []).forEach((dir) => {%>
|
85
|
-
resolveApp('<%= dir %>'),<% }) %>
|
86
|
-
],
|
87
|
-
watchPaths: [<% (watchPaths || []).forEach((dir) => { %>
|
88
|
-
resolveApp('<%= dir %>'),<% }) %>
|
89
|
-
],
|
90
|
-
};
|
91
|
-
|
92
|
-
module.exports.moduleFileExtensions = moduleFileExtensions;
|
@@ -1,25 +0,0 @@
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies, global-require */
|
2
|
-
if (typeof Promise === 'undefined') {
|
3
|
-
// Rejection tracking prevents a common issue where React gets into an
|
4
|
-
// inconsistent state due to an error, but it gets swallowed by a Promise,
|
5
|
-
// and the user has no idea what causes React's erratic future behavior.
|
6
|
-
require('promise/lib/rejection-tracking').enable();
|
7
|
-
window.Promise = require('promise/lib/es6-extensions.js');
|
8
|
-
}
|
9
|
-
|
10
|
-
// fetch() polyfill for making API calls.
|
11
|
-
require('whatwg-fetch');
|
12
|
-
|
13
|
-
require('core-js/es6/map');
|
14
|
-
require('core-js/es6/set');
|
15
|
-
require('raf/polyfill');
|
16
|
-
|
17
|
-
// Object.assign() is commonly used with React.
|
18
|
-
// It will use the native implementation if it's present and isn't buggy.
|
19
|
-
Object.assign = require('object-assign');
|
20
|
-
|
21
|
-
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
|
22
|
-
// We don't polyfill it in the browser--this is user's responsibility.
|
23
|
-
if (process.env.NODE_ENV === 'test') {
|
24
|
-
require('raf').polyfill(global);
|
25
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
const config = require('./config');
|
2
|
-
|
3
|
-
module.exports = ({ options }) =>
|
4
|
-
Object.assign(
|
5
|
-
{},
|
6
|
-
config.postcss,
|
7
|
-
(
|
8
|
-
typeof options.env !== 'undefined' &&
|
9
|
-
typeof config.postcss.env !== 'undefined' &&
|
10
|
-
typeof config.postcss.env[options.env] !== 'undefined'
|
11
|
-
) ? config.postcss.env[options.env] : null,
|
12
|
-
);
|
@@ -1,158 +0,0 @@
|
|
1
|
-
/* eslint-disable no-console, global-require */
|
2
|
-
/* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, import/order */
|
3
|
-
const program = require('commander');
|
4
|
-
|
5
|
-
program
|
6
|
-
.version('0.1.0')
|
7
|
-
.option(
|
8
|
-
'-c, --config [value]',
|
9
|
-
'Webpack configuration',
|
10
|
-
(val, configs) => (configs === null ? [val] : [...configs, val]),
|
11
|
-
null,
|
12
|
-
)
|
13
|
-
.parse(process.argv);
|
14
|
-
|
15
|
-
// Do this as the first thing so that any code reading it knows the right env.
|
16
|
-
process.env.BABEL_ENV = 'production';
|
17
|
-
process.env.NODE_ENV = 'production';
|
18
|
-
|
19
|
-
// Makes the script crash on unhandled rejections instead of silently
|
20
|
-
// ignoring them. In the future, promise rejections that are not handled will
|
21
|
-
// terminate the Node.js process with a non-zero exit code.
|
22
|
-
process.on('unhandledRejection', (err) => {
|
23
|
-
throw err;
|
24
|
-
});
|
25
|
-
|
26
|
-
// Ensure environment variables are read.
|
27
|
-
require('../env');
|
28
|
-
|
29
|
-
const path = require('path');
|
30
|
-
const chalk = require('chalk');
|
31
|
-
const glob = require('glob');
|
32
|
-
const fs = require('fs-extra');
|
33
|
-
const webpack = require('webpack');
|
34
|
-
const defaultWebpackConfig = require('../webpack.config.prod');
|
35
|
-
const paths = require('../paths');
|
36
|
-
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
37
|
-
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
38
|
-
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
39
|
-
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
40
|
-
const printBuildError = require('react-dev-utils/printBuildError');
|
41
|
-
|
42
|
-
const { measureFileSizesBeforeBuild, printFileSizesAfterBuild } = FileSizeReporter;
|
43
|
-
const useYarn = fs.existsSync(paths.yarnLockFile);
|
44
|
-
|
45
|
-
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
46
|
-
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
47
|
-
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
48
|
-
|
49
|
-
const webpackConfigs = program.config !== null
|
50
|
-
? program.config.map(configPath => require(path.join(process.env.PWD, configPath)))
|
51
|
-
: [defaultWebpackConfig];
|
52
|
-
|
53
|
-
// Warn and crash if required files are missing
|
54
|
-
const entries = webpackConfigs.reduce(
|
55
|
-
(allEntries, webpackConfig) => [...allEntries, ...webpackConfig.entry],
|
56
|
-
[],
|
57
|
-
);
|
58
|
-
if (!checkRequiredFiles(entries)) {
|
59
|
-
process.exit(1);
|
60
|
-
}
|
61
|
-
|
62
|
-
// Create the production build and print the deployment instructions.
|
63
|
-
function build(webpackConfig, previousFileSizes) {
|
64
|
-
console.log('Creating an optimized production build...');
|
65
|
-
const compiler = webpack(webpackConfig);
|
66
|
-
return new Promise((resolve, reject) => {
|
67
|
-
compiler.run((err, stats) => {
|
68
|
-
if (err) {
|
69
|
-
return reject(err);
|
70
|
-
}
|
71
|
-
const messages = formatWebpackMessages(stats.toJson({}, true));
|
72
|
-
if (messages.errors.length) {
|
73
|
-
// Only keep the first error. Others are often indicative
|
74
|
-
// of the same problem, but confuse the reader with noise.
|
75
|
-
if (messages.errors.length > 1) {
|
76
|
-
messages.errors.length = 1;
|
77
|
-
}
|
78
|
-
return reject(new Error(messages.errors.join('\n\n')));
|
79
|
-
}
|
80
|
-
if (
|
81
|
-
process.env.CI &&
|
82
|
-
(typeof process.env.CI !== 'string' || process.env.CI.toLowerCase() !== 'false') &&
|
83
|
-
messages.warnings.length
|
84
|
-
) {
|
85
|
-
console.log(chalk.yellow('\nTreating warnings as errors because process.env.CI = true.\n' +
|
86
|
-
'Most CI servers set it automatically.\n'));
|
87
|
-
return reject(new Error(messages.warnings.join('\n\n')));
|
88
|
-
}
|
89
|
-
return resolve({
|
90
|
-
webpackConfig,
|
91
|
-
buildPath: webpackConfig.output.path,
|
92
|
-
stats,
|
93
|
-
previousFileSizes,
|
94
|
-
warnings: messages.warnings,
|
95
|
-
});
|
96
|
-
});
|
97
|
-
});
|
98
|
-
}
|
99
|
-
|
100
|
-
// First, read the current file sizes in build directory.
|
101
|
-
// This lets us display how much they changed later.
|
102
|
-
Promise.all(webpackConfigs.map(conf => measureFileSizesBeforeBuild(conf.output.path)))
|
103
|
-
.then((previousSizes) => {
|
104
|
-
// Merge with the public folder
|
105
|
-
paths.emptyPaths.forEach((dir) => {
|
106
|
-
glob.sync(dir).forEach((file) => {
|
107
|
-
fs.removeSync(file);
|
108
|
-
});
|
109
|
-
});
|
110
|
-
|
111
|
-
// prettier-ignore
|
112
|
-
return webpackConfigs.reduce(
|
113
|
-
(lastPromise, webpackConfig, index) => lastPromise.then(responses => (
|
114
|
-
build(webpackConfig, previousSizes[index]).then(response => [
|
115
|
-
...responses,
|
116
|
-
response,
|
117
|
-
])
|
118
|
-
)),
|
119
|
-
Promise.resolve([]),
|
120
|
-
);
|
121
|
-
})
|
122
|
-
.then(
|
123
|
-
(builds) => {
|
124
|
-
builds.forEach(({
|
125
|
-
webpackConfig, stats, buildPath, previousFileSizes, warnings,
|
126
|
-
}) => {
|
127
|
-
if (warnings.length) {
|
128
|
-
console.log(chalk.yellow('Compiled with warnings.\n'));
|
129
|
-
console.log(warnings.join('\n\n'));
|
130
|
-
console.log(`\nSearch for the ${chalk.underline(chalk.yellow('keywords'))} to learn more about each warning.`);
|
131
|
-
console.log(`To ignore, add ${chalk.cyan('// eslint-disable-next-line')} to the line before.\n`);
|
132
|
-
} else {
|
133
|
-
console.log(chalk.green('Compiled successfully.\n'));
|
134
|
-
}
|
135
|
-
|
136
|
-
console.log('File sizes after gzip:\n');
|
137
|
-
console.log(buildPath);
|
138
|
-
printFileSizesAfterBuild(
|
139
|
-
stats,
|
140
|
-
previousFileSizes,
|
141
|
-
buildPath,
|
142
|
-
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
143
|
-
WARN_AFTER_CHUNK_GZIP_SIZE,
|
144
|
-
);
|
145
|
-
|
146
|
-
const appPackage = require(paths.appPackageJson);
|
147
|
-
const { publicUrl } = paths;
|
148
|
-
const { publicPath } = webpackConfig.output;
|
149
|
-
const buildFolder = path.relative(process.cwd(), buildPath);
|
150
|
-
printHostingInstructions(appPackage, publicUrl, publicPath, buildFolder, useYarn);
|
151
|
-
});
|
152
|
-
},
|
153
|
-
(err) => {
|
154
|
-
console.log(chalk.red('Failed to compile.\n'));
|
155
|
-
printBuildError(err);
|
156
|
-
process.exit(1);
|
157
|
-
},
|
158
|
-
);
|
@@ -1,59 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
3
|
-
const imagemin = require('imagemin');
|
4
|
-
const imageminMozjpeg = require('imagemin-mozjpeg');
|
5
|
-
const imageminPngquant = require('imagemin-pngquant');
|
6
|
-
const imageminSvgo = require('imagemin-svgo');
|
7
|
-
const glob = require('glob');
|
8
|
-
const path = require('path');
|
9
|
-
const fs = require('fs');
|
10
|
-
const chalk = require('chalk');
|
11
|
-
const prettyBytes = require('pretty-bytes');
|
12
|
-
const imageminConfig = require('./config').imagemin;
|
13
|
-
|
14
|
-
function minifyImage(srcPath, output) {
|
15
|
-
const stats = fs.statSync(srcPath);
|
16
|
-
const originalSize = stats.size;
|
17
|
-
|
18
|
-
imagemin([srcPath], output, {
|
19
|
-
plugins: [
|
20
|
-
imageminMozjpeg(),
|
21
|
-
imageminPngquant(imageminConfig.pngquant),
|
22
|
-
imageminSvgo(imageminConfig.svgo),
|
23
|
-
],
|
24
|
-
}).then((files) => {
|
25
|
-
let saved;
|
26
|
-
let optimizedSize;
|
27
|
-
let percent;
|
28
|
-
let savedMsg;
|
29
|
-
let msg;
|
30
|
-
const fl = files.length;
|
31
|
-
for (let i = 0; i < fl; i += 1) {
|
32
|
-
optimizedSize = files[i].data.length;
|
33
|
-
saved = originalSize - optimizedSize;
|
34
|
-
percent = originalSize > 0 ? (saved / originalSize) * 100 : 0;
|
35
|
-
savedMsg = `saved ${prettyBytes(saved)} - ${percent.toFixed(1).replace(/\.0$/, '')}%`;
|
36
|
-
msg = saved > 0 ? savedMsg : 'already optimized';
|
37
|
-
// eslint-disable-next-line no-console
|
38
|
-
console.log(`${chalk.green('✔')} ${srcPath} ${chalk.yellow('>')} ${files[i].path} - ${msg}`);
|
39
|
-
}
|
40
|
-
});
|
41
|
-
}
|
42
|
-
|
43
|
-
const processFile = fileGlob => (
|
44
|
-
(er, files) => {
|
45
|
-
const basePath = fileGlob.substr(0, fileGlob.indexOf('*'));
|
46
|
-
let srcPath;
|
47
|
-
let relativePath;
|
48
|
-
const fl = files.length;
|
49
|
-
for (let i = 0; i < fl; i += 1) {
|
50
|
-
srcPath = files[i];
|
51
|
-
relativePath = srcPath.replace(basePath, '');
|
52
|
-
minifyImage(srcPath, path.join(imageminConfig.output, path.dirname(relativePath)));
|
53
|
-
}
|
54
|
-
}
|
55
|
-
);
|
56
|
-
|
57
|
-
for (let i = 0, fl = imageminConfig.files.length; i < fl; i += 1) {
|
58
|
-
glob(imageminConfig.files[i], {}, processFile(imageminConfig.files[i]));
|
59
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
3
|
-
const program = require('commander');
|
4
|
-
const modernizr = require('customizr');
|
5
|
-
const config = require('./config').modernizr || {};
|
6
|
-
|
7
|
-
program
|
8
|
-
.option('-d, --dist', 'Production build')
|
9
|
-
.parse(process.argv);
|
10
|
-
|
11
|
-
let settings = {
|
12
|
-
...config,
|
13
|
-
};
|
14
|
-
if (program.dist) {
|
15
|
-
settings.dest = '<%= outputPath %>';
|
16
|
-
settings.uglify = true;
|
17
|
-
settings.cache = false;
|
18
|
-
}
|
19
|
-
|
20
|
-
modernizr(settings, () => {
|
21
|
-
|
22
|
-
});
|
@@ -1,176 +0,0 @@
|
|
1
|
-
/* eslint-disable no-console, global-require */
|
2
|
-
/* eslint-disable import/no-extraneous-dependencies, import/no-dynamic-require, import/order */
|
3
|
-
const program = require('commander');
|
4
|
-
|
5
|
-
program
|
6
|
-
.version('0.1.0')
|
7
|
-
.option(
|
8
|
-
'-c, --config [value]',
|
9
|
-
'Webpack configuration',
|
10
|
-
(val, configs) => (configs === null ? [val] : [...configs, val]),
|
11
|
-
null,
|
12
|
-
)
|
13
|
-
.parse(process.argv);
|
14
|
-
|
15
|
-
// Do this as the first thing so that any code reading it knows the right env.
|
16
|
-
process.env.BABEL_ENV = 'development';
|
17
|
-
process.env.NODE_ENV = 'development';
|
18
|
-
|
19
|
-
// Makes the script crash on unhandled rejections instead of silently
|
20
|
-
// ignoring them. In the future, promise rejections that are not handled will
|
21
|
-
// terminate the Node.js process with a non-zero exit code.
|
22
|
-
process.on('unhandledRejection', err => {
|
23
|
-
throw err;
|
24
|
-
});
|
25
|
-
|
26
|
-
// Ensure environment variables are read.
|
27
|
-
require('../env');
|
28
|
-
|
29
|
-
const fs = require('fs');
|
30
|
-
const path = require('path');
|
31
|
-
const chalk = require('chalk');
|
32
|
-
const webpack = require('webpack');
|
33
|
-
const isArray = require('lodash/isArray');
|
34
|
-
const WebpackDevServer = require('webpack-dev-server');
|
35
|
-
const clearConsole = require('react-dev-utils/clearConsole');
|
36
|
-
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
37
|
-
const {
|
38
|
-
choosePort,
|
39
|
-
createCompiler,
|
40
|
-
prepareProxy,
|
41
|
-
prepareUrls,
|
42
|
-
} = require('react-dev-utils/WebpackDevServerUtils');
|
43
|
-
const openBrowser = require('react-dev-utils/openBrowser');
|
44
|
-
const paths = require('../paths');
|
45
|
-
const { webpackDevServer: config } = require('../config');
|
46
|
-
const defaultWebpackConfig = require('../webpack.config.dev');
|
47
|
-
const createDevServerConfig = require('../webpackDevServer.config');
|
48
|
-
|
49
|
-
const useYarn = fs.existsSync(paths.yarnLockFile);
|
50
|
-
const isInteractive = process.stdout.isTTY;
|
51
|
-
|
52
|
-
const webpackConfigs =
|
53
|
-
program.config !== null
|
54
|
-
? program.config.map(configPath => require(path.join(process.env.PWD, configPath)))
|
55
|
-
: defaultWebpackConfig;
|
56
|
-
|
57
|
-
const entries = isArray(webpackConfigs)
|
58
|
-
? webpackConfigs.reduce(
|
59
|
-
(allEntries, webpackConfig) => [...allEntries, ...webpackConfig.entry],
|
60
|
-
[],
|
61
|
-
)
|
62
|
-
: webpackConfigs.entry;
|
63
|
-
|
64
|
-
// Warn and crash if required files are missing
|
65
|
-
if (!checkRequiredFiles(entries)) {
|
66
|
-
process.exit(1);
|
67
|
-
}
|
68
|
-
|
69
|
-
// Tools like Cloud9 rely on this.
|
70
|
-
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
71
|
-
const HOST = process.env.HOST || config.browserHost || '0.0.0.0';
|
72
|
-
|
73
|
-
if (process.env.HOST) {
|
74
|
-
console.log(
|
75
|
-
chalk.cyan(
|
76
|
-
`Attempting to bind to HOST environment variable: ${chalk.yellow(
|
77
|
-
chalk.bold(process.env.HOST),
|
78
|
-
)}`,
|
79
|
-
),
|
80
|
-
);
|
81
|
-
console.log(
|
82
|
-
"If this was unintentional, check that you haven't mistakenly set it in your shell.",
|
83
|
-
);
|
84
|
-
console.log(`Learn more here: ${chalk.yellow('http://bit.ly/CRA-advanced-config')}`);
|
85
|
-
console.log();
|
86
|
-
}
|
87
|
-
|
88
|
-
// We require that you explictly set browsers and do not fall back to
|
89
|
-
// browserslist defaults.
|
90
|
-
const { checkBrowsers } = require('react-dev-utils/browsersHelper');
|
91
|
-
|
92
|
-
function mayProxy(pathname) {
|
93
|
-
const maybePublicPath = path.resolve(paths.appPublic, pathname.slice(1));
|
94
|
-
return (
|
95
|
-
!pathname.startsWith('/sockjs-node') &&
|
96
|
-
(!fs.existsSync(maybePublicPath) || fs.lstatSync(maybePublicPath).isDirectory())
|
97
|
-
);
|
98
|
-
}
|
99
|
-
|
100
|
-
checkBrowsers(paths.appPath, isInteractive)
|
101
|
-
.then(() => choosePort(HOST, DEFAULT_PORT))
|
102
|
-
.then(port => {
|
103
|
-
if (port == null) {
|
104
|
-
// We have not found a port.
|
105
|
-
return;
|
106
|
-
}
|
107
|
-
|
108
|
-
const protocol = process.env.HTTPS === 'true' || config.https ? 'https' : 'http';
|
109
|
-
const appName = require(paths.appPackageJson).name;
|
110
|
-
const urls = prepareUrls(protocol, HOST, port);
|
111
|
-
let devServer;
|
112
|
-
const devSocket = {
|
113
|
-
warnings: warnings => devServer.sockWrite(devServer.sockets, 'warnings', warnings),
|
114
|
-
errors: errors => devServer.sockWrite(devServer.sockets, 'errors', errors),
|
115
|
-
};
|
116
|
-
// Create a webpack compiler that is configured with custom messages.
|
117
|
-
// const compiler = createCompiler(webpack, webpackConfigs, appName, urls, useYarn);
|
118
|
-
const compiler = createCompiler({
|
119
|
-
appName,
|
120
|
-
urls,
|
121
|
-
useYarn,
|
122
|
-
webpack,
|
123
|
-
devSocket,
|
124
|
-
config: webpackConfigs,
|
125
|
-
});
|
126
|
-
// Load proxy config
|
127
|
-
const proxySetting = config.proxy || require(paths.appPackageJson).proxy;
|
128
|
-
const proxyConfig = prepareProxy(proxySetting, paths.appPublic) || null;
|
129
|
-
// Serve webpack assets generated by the compiler over a web server.
|
130
|
-
const serverConfig = createDevServerConfig(
|
131
|
-
// proxyConfig,
|
132
|
-
proxyConfig !== null
|
133
|
-
? [
|
134
|
-
{
|
135
|
-
...proxyConfig[0],
|
136
|
-
context(pathname, req) {
|
137
|
-
return (
|
138
|
-
req.method !== 'GET' ||
|
139
|
-
pathname === '/' ||
|
140
|
-
(mayProxy(pathname) && req.headers.accept)
|
141
|
-
);
|
142
|
-
},
|
143
|
-
changeOrigin: false,
|
144
|
-
autoRewrite: true,
|
145
|
-
},
|
146
|
-
]
|
147
|
-
: null,
|
148
|
-
urls.lanUrlForConfig,
|
149
|
-
);
|
150
|
-
devServer = new WebpackDevServer(compiler, serverConfig);
|
151
|
-
// Launch WebpackDevServer.
|
152
|
-
devServer.listen(port, HOST, err => {
|
153
|
-
if (err) {
|
154
|
-
console.log(err);
|
155
|
-
return;
|
156
|
-
}
|
157
|
-
if (isInteractive) {
|
158
|
-
clearConsole();
|
159
|
-
}
|
160
|
-
console.log(chalk.cyan('Starting the development server...\n'));
|
161
|
-
openBrowser(urls.localUrlForBrowser);
|
162
|
-
});
|
163
|
-
|
164
|
-
['SIGINT', 'SIGTERM'].forEach(sig => {
|
165
|
-
process.on(sig, () => {
|
166
|
-
devServer.close();
|
167
|
-
process.exit();
|
168
|
-
});
|
169
|
-
});
|
170
|
-
})
|
171
|
-
.catch(err => {
|
172
|
-
if (err && err.message) {
|
173
|
-
console.log(err);
|
174
|
-
}
|
175
|
-
process.exit(1);
|
176
|
-
});
|
@@ -1,11 +0,0 @@
|
|
1
|
-
const path = require('path');
|
2
|
-
const LOCAL_IDENT_NAME = require('../config').webpack.cssLocalIdent;
|
3
|
-
|
4
|
-
module.exports = (localIdentName, localName, filePath) => {
|
5
|
-
const directories = path.dirname(filePath).split('/');
|
6
|
-
const dir = directories[directories.length - 1];
|
7
|
-
const basename = path.basename(filePath).replace(/(\.module|\.global)?\.s?css$/i, '');
|
8
|
-
const name = dir !== 'styles' ? `${dir}-${basename}` : basename;
|
9
|
-
return (localIdentName || LOCAL_IDENT_NAME).replace(/\[\s*name\s*\]/gi, name)
|
10
|
-
.replace(/\[\s*local\s*\]/gi, localName);
|
11
|
-
};
|