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,394 +0,0 @@
|
|
1
|
-
const path = require('path');
|
2
|
-
const webpack = require('webpack');
|
3
|
-
const PnpWebpackPlugin = require('pnp-webpack-plugin');
|
4
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
5
|
-
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
6
|
-
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
7
|
-
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
8
|
-
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
9
|
-
const ManifestPlugin = require('webpack-manifest-plugin');
|
10
|
-
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
|
11
|
-
const getClientEnvironment = require('./env');
|
12
|
-
const paths = require('./paths');
|
13
|
-
const config = require('./config').webpack;
|
14
|
-
const getLocalIdent = require('./utils/getLocalIdent');
|
15
|
-
const getConfigValue = require('./utils/getConfigValue');
|
16
|
-
|
17
|
-
// Webpack uses `publicPath` to determine where the app is being served from.
|
18
|
-
// In development, we always serve from the root. This makes config easier.
|
19
|
-
const publicPath = getConfigValue(config.publicPath);
|
20
|
-
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
21
|
-
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
22
|
-
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
23
|
-
const publicUrl = '';
|
24
|
-
// Get environment variables to inject into our app.
|
25
|
-
const env = getClientEnvironment(publicUrl);
|
26
|
-
|
27
|
-
// Options for PostCSS as we reference these options twice
|
28
|
-
// Adds vendor prefixing based on your specified browser support in
|
29
|
-
// package.json
|
30
|
-
const postCSSLoaderOptions = {
|
31
|
-
config: {
|
32
|
-
path: path.join(__dirname, './postcss.config.js'),
|
33
|
-
ctx: {
|
34
|
-
env,
|
35
|
-
},
|
36
|
-
},
|
37
|
-
};
|
38
|
-
|
39
|
-
// style files regexes
|
40
|
-
const cssRegex = getConfigValue(config.cssRegex);
|
41
|
-
const cssModuleRegex = getConfigValue(config.cssModuleRegex);
|
42
|
-
const sassRegex = getConfigValue(config.sassRegex);
|
43
|
-
const sassModuleRegex = getConfigValue(config.sassModuleRegex);
|
44
|
-
|
45
|
-
// common function to get style loaders
|
46
|
-
const getStyleLoaders = (cssOptions, preProcessor) => {
|
47
|
-
const loaders = [
|
48
|
-
require.resolve('style-loader'),
|
49
|
-
{
|
50
|
-
loader: require.resolve('css-loader'),
|
51
|
-
options: cssOptions,
|
52
|
-
},
|
53
|
-
{
|
54
|
-
loader: require.resolve('postcss-loader'),
|
55
|
-
options: postCSSLoaderOptions,
|
56
|
-
},
|
57
|
-
];
|
58
|
-
if (preProcessor) {
|
59
|
-
loaders.push(require.resolve(preProcessor));
|
60
|
-
}
|
61
|
-
return loaders;
|
62
|
-
};
|
63
|
-
|
64
|
-
// This is the development configuration.
|
65
|
-
// It is focused on developer experience and fast rebuilds.
|
66
|
-
// The production configuration is different and lives in a separate file.
|
67
|
-
module.exports = {
|
68
|
-
mode: 'development',
|
69
|
-
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
70
|
-
// See the discussion in https://github.com/facebook/create-react-app/issues/343
|
71
|
-
devtool: 'cheap-module-source-map',
|
72
|
-
// These are the "entry points" to our application.
|
73
|
-
// This means they will be the "root" imports that are included in JS bundle.
|
74
|
-
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
75
|
-
entry: [
|
76
|
-
// Include an alternative client for WebpackDevServer. A client's job is to
|
77
|
-
// connect to WebpackDevServer by a socket and get notified about changes.
|
78
|
-
// When you save a file, the client will either apply hot updates (in case
|
79
|
-
// of CSS changes), or refresh the page (in case of JS changes). When you
|
80
|
-
// make a syntax error, this client will display a syntax error overlay.
|
81
|
-
// Note: instead of the default WebpackDevServer client, we use a custom one
|
82
|
-
// to bring better experience for Create React App users. You can replace
|
83
|
-
// the line below with these two lines if you prefer the stock client:
|
84
|
-
// require.resolve('webpack-dev-server/client') + '?/',
|
85
|
-
// require.resolve('webpack/hot/dev-server'),
|
86
|
-
require.resolve('react-dev-utils/webpackHotDevClient'),
|
87
|
-
// Finally, this is your app's code:
|
88
|
-
paths.appIndexJs,
|
89
|
-
// We include the app code last so that if there is a runtime error during
|
90
|
-
// initialization, it doesn't blow up the WebpackDevServer client, and
|
91
|
-
// changing JS code would still trigger a refresh.
|
92
|
-
],
|
93
|
-
output: {
|
94
|
-
// Add /* filename */ comments to generated require()s in the output.
|
95
|
-
pathinfo: true,
|
96
|
-
// This does not produce a real file. It's just the virtual path that is
|
97
|
-
// served by WebpackDevServer in development. This is the JS bundle
|
98
|
-
// containing code from all our entry points, and the Webpack runtime.
|
99
|
-
filename: getConfigValue(config.filename),
|
100
|
-
// There are also additional JS chunk files if you use code splitting.
|
101
|
-
chunkFilename: getConfigValue(config.chunkFilename),
|
102
|
-
// This is the URL that app is served from. We use "/" in development.
|
103
|
-
publicPath,
|
104
|
-
// Point sourcemap entries to original disk location (format as URL on Windows)
|
105
|
-
devtoolModuleFilenameTemplate: info => path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
106
|
-
},
|
107
|
-
optimization: {
|
108
|
-
// Automatically split vendor and commons
|
109
|
-
// https://twitter.com/wSokra/status/969633336732905474
|
110
|
-
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
|
111
|
-
splitChunks: {
|
112
|
-
chunks: (paths.appHtml || null) !== null ? 'all' : 'async',
|
113
|
-
name: false,
|
114
|
-
},
|
115
|
-
// Keep the runtime chunk seperated to enable long term caching
|
116
|
-
// https://twitter.com/wSokra/status/969679223278505985
|
117
|
-
runtimeChunk: (paths.appHtml || null) !== null,
|
118
|
-
},
|
119
|
-
resolve: {
|
120
|
-
// This allows you to set a fallback for where Webpack should look for modules.
|
121
|
-
// We placed these paths second because we want `node_modules` to "win"
|
122
|
-
// if there are any conflicts. This matches Node resolution mechanism.
|
123
|
-
// https://github.com/facebook/create-react-app/issues/253
|
124
|
-
modules: ['node_modules'].concat(
|
125
|
-
// It is guaranteed to exist because we tweak it in `env.js`
|
126
|
-
process.env.NODE_PATH.split(path.delimiter).filter(Boolean),
|
127
|
-
),
|
128
|
-
// These are the reasonable defaults supported by the Node ecosystem.
|
129
|
-
// We also include JSX as a common component filename extension to support
|
130
|
-
// some tools, although we do not recommend using it, see:
|
131
|
-
// https://github.com/facebook/create-react-app/issues/290
|
132
|
-
// `web` extension prefixes have been added for better support
|
133
|
-
// for React Native Web.
|
134
|
-
extensions: paths.moduleFileExtensions.map(ext => `.${ext}`),
|
135
|
-
alias: {
|
136
|
-
// Support React Native Web
|
137
|
-
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
138
|
-
'react-native': 'react-native-web',
|
139
|
-
},
|
140
|
-
plugins: [
|
141
|
-
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
|
142
|
-
// guards against forgotten dependencies and such.
|
143
|
-
PnpWebpackPlugin,
|
144
|
-
// Prevents users from importing files from outside of src/ (or node_modules/).
|
145
|
-
// This often causes confusion because we only process files within src/ with babel.
|
146
|
-
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
147
|
-
// please link the files into your node_modules/ and let module-resolution kick in.
|
148
|
-
// Make sure your source files are compiled, as they will not be processed in any way.
|
149
|
-
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
150
|
-
],
|
151
|
-
},
|
152
|
-
resolveLoader: {
|
153
|
-
plugins: [
|
154
|
-
// Also related to Plug'n'Play, but this time it tells Webpack to load its loaders
|
155
|
-
// from the current package.
|
156
|
-
PnpWebpackPlugin.moduleLoader(module),
|
157
|
-
],
|
158
|
-
},
|
159
|
-
module: {
|
160
|
-
strictExportPresence: true,
|
161
|
-
rules: [
|
162
|
-
// Disable require.ensure as it's not a standard language feature.
|
163
|
-
{ parser: { requireEnsure: false } },
|
164
|
-
|
165
|
-
// First, run the linter.
|
166
|
-
// It's important to do this before Babel processes the JS.
|
167
|
-
{
|
168
|
-
test: /\.(js|mjs|jsx)$/,
|
169
|
-
enforce: 'pre',
|
170
|
-
use: [
|
171
|
-
{
|
172
|
-
options: {
|
173
|
-
formatter: require.resolve('react-dev-utils/eslintFormatter'),
|
174
|
-
eslintPath: require.resolve('eslint'),
|
175
|
-
rules: {
|
176
|
-
'no-console': ['warn', { allow: ['warn', 'error'] }],
|
177
|
-
},
|
178
|
-
},
|
179
|
-
loader: require.resolve('eslint-loader'),
|
180
|
-
},
|
181
|
-
],
|
182
|
-
include: paths.appSrc,
|
183
|
-
},
|
184
|
-
{
|
185
|
-
// "oneOf" will traverse all following loaders until one will
|
186
|
-
// match the requirements. When no loader matches it will fall
|
187
|
-
// back to the "file" loader at the end of the loader list.
|
188
|
-
oneOf: [
|
189
|
-
// "url" loader works like "file" loader except that it embeds assets
|
190
|
-
// smaller than specified limit in bytes as data URLs to avoid requests.
|
191
|
-
// A missing `test` is equivalent to a match.
|
192
|
-
{
|
193
|
-
test: [/\.woff$/, /\.woff2$/, /\.otf$/, /\.ttf$/, /\.otf$/, /\.eot$/, /\.svg$/],
|
194
|
-
include: [
|
195
|
-
/\/fonts\//,
|
196
|
-
],
|
197
|
-
loader: require.resolve('file-loader'),
|
198
|
-
options: {
|
199
|
-
limit: 10000,
|
200
|
-
name: getConfigValue(config.fontFilename),
|
201
|
-
},
|
202
|
-
},
|
203
|
-
{
|
204
|
-
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.svg$/],
|
205
|
-
loader: require.resolve('url-loader'),
|
206
|
-
options: {
|
207
|
-
limit: 10000,
|
208
|
-
name: getConfigValue(config.imageFilename),
|
209
|
-
},
|
210
|
-
},
|
211
|
-
// Process JS with Babel.
|
212
|
-
{
|
213
|
-
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
214
|
-
include: paths.appSrc,
|
215
|
-
loader: require.resolve('babel-loader'),
|
216
|
-
options: {
|
217
|
-
customize: require.resolve(
|
218
|
-
'babel-preset-react-app/webpack-overrides',
|
219
|
-
),
|
220
|
-
plugins: [
|
221
|
-
[
|
222
|
-
require.resolve('babel-plugin-named-asset-import'),
|
223
|
-
{
|
224
|
-
loaderMap: {
|
225
|
-
svg: {
|
226
|
-
ReactComponent: '@svgr/webpack?-prettier,-svgo![path]',
|
227
|
-
},
|
228
|
-
},
|
229
|
-
},
|
230
|
-
],
|
231
|
-
],
|
232
|
-
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
233
|
-
// It enables caching results in ./node_modules/.cache/babel-loader/
|
234
|
-
// directory for faster rebuilds.
|
235
|
-
cacheDirectory: true,
|
236
|
-
// Don't waste time on Gzipping the cache
|
237
|
-
cacheCompression: false,
|
238
|
-
},
|
239
|
-
},
|
240
|
-
// For dependencies
|
241
|
-
{
|
242
|
-
test: /\.(js|mjs)$/,
|
243
|
-
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
244
|
-
loader: require.resolve('babel-loader'),
|
245
|
-
options: {
|
246
|
-
babelrc: false,
|
247
|
-
configFile: false,
|
248
|
-
compact: false,
|
249
|
-
presets: [
|
250
|
-
[
|
251
|
-
require.resolve('babel-preset-react-app/dependencies'),
|
252
|
-
{ helpers: true },
|
253
|
-
],
|
254
|
-
],
|
255
|
-
cacheDirectory: true,
|
256
|
-
// Don't waste time on Gzipping the cache
|
257
|
-
cacheCompression: false,
|
258
|
-
// If an error happens in a package, it's possible to be
|
259
|
-
// because it was compiled. Thus, we don't want the browser
|
260
|
-
// debugger to show the original code. Instead, the code
|
261
|
-
// being evaluated would be much more helpful.
|
262
|
-
sourceMaps: false,
|
263
|
-
},
|
264
|
-
},
|
265
|
-
// Global CSS
|
266
|
-
{
|
267
|
-
test: cssRegex,
|
268
|
-
use: getStyleLoaders({
|
269
|
-
importLoaders: 1,
|
270
|
-
}),
|
271
|
-
},
|
272
|
-
// CSS modules
|
273
|
-
{
|
274
|
-
test: cssModuleRegex,
|
275
|
-
exclude: cssRegex,
|
276
|
-
use: getStyleLoaders({
|
277
|
-
importLoaders: 1,
|
278
|
-
modules: {
|
279
|
-
localIdentName: getConfigValue(config.cssLocalIdent),
|
280
|
-
// prettier-ignore
|
281
|
-
getLocalIdent: (context, localIdentName, localName) => (
|
282
|
-
getLocalIdent(localIdentName, localName, context.resourcePath)
|
283
|
-
),
|
284
|
-
},
|
285
|
-
}),
|
286
|
-
},
|
287
|
-
// Global SASS
|
288
|
-
{
|
289
|
-
test: sassRegex,
|
290
|
-
use: getStyleLoaders({ importLoaders: 2 }, 'sass-loader'),
|
291
|
-
},
|
292
|
-
// SASS modules
|
293
|
-
{
|
294
|
-
test: sassModuleRegex,
|
295
|
-
exclude: sassRegex,
|
296
|
-
use: getStyleLoaders(
|
297
|
-
{
|
298
|
-
importLoaders: 2,
|
299
|
-
modules: {
|
300
|
-
localIdentName: getConfigValue(config.cssLocalIdent),
|
301
|
-
// prettier-ignore
|
302
|
-
getLocalIdent: (context, localIdentName, localName) => (
|
303
|
-
getLocalIdent(
|
304
|
-
localIdentName,
|
305
|
-
localName,
|
306
|
-
context.resourcePath,
|
307
|
-
)
|
308
|
-
),
|
309
|
-
},
|
310
|
-
},
|
311
|
-
'sass-loader',
|
312
|
-
),
|
313
|
-
},
|
314
|
-
// "file" loader makes sure those assets get served by WebpackDevServer.
|
315
|
-
// When you `import` an asset, you get its (virtual) filename.
|
316
|
-
// In production, they would get copied to the `build` folder.
|
317
|
-
// This loader doesn't use a "test" so it will catch all modules
|
318
|
-
// that fall through the other loaders.
|
319
|
-
{
|
320
|
-
// Exclude `js` files to keep "css" loader working as it injects
|
321
|
-
// its runtime that would otherwise processed through "file" loader.
|
322
|
-
// Also exclude `html` and `json` extensions so they get processed
|
323
|
-
// by webpacks internal loaders.
|
324
|
-
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.html\.ejs$/, /\.json$/],
|
325
|
-
loader: require.resolve('file-loader'),
|
326
|
-
options: {
|
327
|
-
name: getConfigValue(config.mediaFilename),
|
328
|
-
},
|
329
|
-
},
|
330
|
-
],
|
331
|
-
},
|
332
|
-
// ** STOP ** Are you adding a new loader?
|
333
|
-
// Make sure to add the new loader(s) before the "file" loader.
|
334
|
-
],
|
335
|
-
},
|
336
|
-
plugins: [
|
337
|
-
// Generates an `index.html` file with the <script> injected.
|
338
|
-
...((paths.appHtml || null) !== null ? [
|
339
|
-
new HtmlWebpackPlugin({
|
340
|
-
inject: true,
|
341
|
-
template: paths.appHtml,
|
342
|
-
}),
|
343
|
-
] : []),
|
344
|
-
// Makes some environment variables available in index.html.
|
345
|
-
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
346
|
-
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
347
|
-
// In development, this will be an empty string.
|
348
|
-
new InterpolateHtmlPlugin(HtmlWebpackPlugin, env.raw),
|
349
|
-
// This gives some necessary context to module not found errors, such as
|
350
|
-
// the requesting resource.
|
351
|
-
new ModuleNotFoundPlugin(paths.appPath),
|
352
|
-
// Makes some environment variables available to the JS code, for example:
|
353
|
-
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
354
|
-
new webpack.DefinePlugin(env.stringified),
|
355
|
-
// This is necessary to emit hot updates (currently CSS only):
|
356
|
-
new webpack.HotModuleReplacementPlugin(),
|
357
|
-
// Watcher doesn't work well if you mistype casing in a path so we use
|
358
|
-
// a plugin that prints an error when you attempt to do this.
|
359
|
-
// See https://github.com/facebook/create-react-app/issues/240
|
360
|
-
new CaseSensitivePathsPlugin(),
|
361
|
-
// If you require a missing module and then `npm install` it, you still have
|
362
|
-
// to restart the development server for Webpack to discover it. This plugin
|
363
|
-
// makes the discovery automatic so you don't have to restart.
|
364
|
-
// See https://github.com/facebook/create-react-app/issues/186
|
365
|
-
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
366
|
-
// Moment.js is an extremely popular library that bundles large locale files
|
367
|
-
// by default due to how Webpack interprets its code. This is a practical
|
368
|
-
// solution that requires the user to opt into importing specific locales.
|
369
|
-
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
370
|
-
// You can remove this if you don't use Moment.js:
|
371
|
-
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
372
|
-
// Ignore react-intl locale except fr and en
|
373
|
-
new webpack.IgnorePlugin(/(?!fr|en)([a-z]{2,3})/, /locale-data/),
|
374
|
-
// Generate a manifest file which contains a mapping of all asset filenames
|
375
|
-
// to their corresponding output file so that tools can pick it up without
|
376
|
-
// having to parse `index.html`.
|
377
|
-
new ManifestPlugin({
|
378
|
-
fileName: 'asset-manifest.json',
|
379
|
-
publicPath,
|
380
|
-
}),
|
381
|
-
],
|
382
|
-
// Some libraries import Node modules but don't use them in the browser.
|
383
|
-
// Tell Webpack to provide empty mocks for them so importing them works.
|
384
|
-
node: {
|
385
|
-
dgram: 'empty',
|
386
|
-
fs: 'empty',
|
387
|
-
net: 'empty',
|
388
|
-
tls: 'empty',
|
389
|
-
child_process: 'empty',
|
390
|
-
},
|
391
|
-
// Turn off performance processing because we utilize
|
392
|
-
// our own hints via the FileSizeReporter
|
393
|
-
performance: false,
|
394
|
-
};
|