Skip to content

Commit 9ba15c5

Browse files
committed
WIP library build step
1 parent d4ba2b2 commit 9ba15c5

File tree

2 files changed

+2
-95
lines changed

2 files changed

+2
-95
lines changed

packages/react-scripts/config/webpack.config.library.js

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010

1111
const path = require('path');
1212
const webpack = require('webpack');
13-
const HtmlWebpackPlugin = require('html-webpack-plugin');
1413
const ExtractTextPlugin = require('extract-text-webpack-plugin');
15-
const ManifestPlugin = require('webpack-manifest-plugin');
16-
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
17-
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
1814
const eslintFormatter = require('react-dev-utils/eslintFormatter');
1915
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2016
const paths = require('./paths');
@@ -93,8 +89,8 @@ module.exports = {
9389
// Generated JS file names (with nested folders).
9490
// There will be one main bundle, and one file per asynchronous chunk.
9591
// We don't currently advertise code splitting but Webpack supports it.
96-
filename: 'static/js/[name].[chunkhash:8].js',
97-
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
92+
filename: 'index.js',
93+
libraryTarget: 'commonjs',
9894
// We inferred the "public path" (such as / or /my-project) from homepage.
9995
publicPath: publicPath,
10096
// Point sourcemap entries to original disk location (format as URL on Windows)
@@ -287,95 +283,15 @@ module.exports = {
287283
],
288284
},
289285
plugins: [
290-
// Makes some environment variables available in index.html.
291-
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
292-
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
293-
// In production, it will be an empty string unless you specify "homepage"
294-
// in `package.json`, in which case it will be the pathname of that URL.
295-
new InterpolateHtmlPlugin(env.raw),
296-
// Generates an `index.html` file with the <script> injected.
297-
new HtmlWebpackPlugin({
298-
inject: true,
299-
template: paths.appHtml,
300-
minify: {
301-
removeComments: true,
302-
collapseWhitespace: true,
303-
removeRedundantAttributes: true,
304-
useShortDoctype: true,
305-
removeEmptyAttributes: true,
306-
removeStyleLinkTypeAttributes: true,
307-
keepClosingSlash: true,
308-
minifyJS: true,
309-
minifyCSS: true,
310-
minifyURLs: true,
311-
},
312-
}),
313286
// Makes some environment variables available to the JS code, for example:
314287
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
315288
// It is absolutely essential that NODE_ENV was set to production here.
316289
// Otherwise React will be compiled in the very slow development mode.
317290
new webpack.DefinePlugin(env.stringified),
318-
// Minify the code.
319-
new webpack.optimize.UglifyJsPlugin({
320-
compress: {
321-
warnings: false,
322-
// Disabled because of an issue with Uglify breaking seemingly valid code:
323-
// https://github.com/facebookincubator/create-react-app/issues/2376
324-
// Pending further investigation:
325-
// https://github.com/mishoo/UglifyJS2/issues/2011
326-
comparisons: false,
327-
},
328-
mangle: {
329-
safari10: true,
330-
},
331-
output: {
332-
comments: false,
333-
// Turned on because emoji and regex is not minified properly using default
334-
// https://github.com/facebookincubator/create-react-app/issues/2488
335-
ascii_only: true,
336-
},
337-
sourceMap: shouldUseSourceMap,
338-
}),
339291
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
340292
new ExtractTextPlugin({
341293
filename: cssFilename,
342294
}),
343-
// Generate a manifest file which contains a mapping of all asset filenames
344-
// to their corresponding output file so that tools can pick it up without
345-
// having to parse `index.html`.
346-
new ManifestPlugin({
347-
fileName: 'asset-manifest.json',
348-
}),
349-
// Generate a service worker script that will precache, and keep up to date,
350-
// the HTML & assets that are part of the Webpack build.
351-
new SWPrecacheWebpackPlugin({
352-
// By default, a cache-busting query parameter is appended to requests
353-
// used to populate the caches, to ensure the responses are fresh.
354-
// If a URL is already hashed by Webpack, then there is no concern
355-
// about it being stale, and the cache-busting can be skipped.
356-
dontCacheBustUrlsMatching: /\.\w{8}\./,
357-
filename: 'service-worker.js',
358-
logger(message) {
359-
if (message.indexOf('Total precache size is') === 0) {
360-
// This message occurs for every build and is a bit too noisy.
361-
return;
362-
}
363-
if (message.indexOf('Skipping static resource') === 0) {
364-
// This message obscures real errors so we ignore it.
365-
// https://github.com/facebookincubator/create-react-app/issues/2612
366-
return;
367-
}
368-
console.log(message);
369-
},
370-
minify: true,
371-
// For unknown URLs, fallback to the index page
372-
navigateFallback: publicUrl + '/index.html',
373-
// Ignores URLs starting from /__ (useful for Firebase):
374-
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
375-
navigateFallbackWhitelist: [/^(?!\/__).*/],
376-
// Don't precache sourcemaps (they're large) and build asset manifest:
377-
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
378-
}),
379295
// Moment.js is an extremely popular library that bundles large locale files
380296
// by default due to how Webpack interprets its code. This is a practical
381297
// solution that requires the user to opt into importing specific locales.

packages/react-scripts/scripts/build-library.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ measureFileSizesBeforeBuild(paths.appBuild)
5555
// Remove all content but keep the directory so that
5656
// if you're in it, you don't end up in Trash
5757
fs.emptyDirSync(paths.appBuild);
58-
// Merge with the public folder
59-
copyPublicFolder();
6058
// Start the webpack build
6159
return build(previousFileSizes);
6260
})
@@ -149,10 +147,3 @@ function build(previousFileSizes) {
149147
});
150148
});
151149
}
152-
153-
function copyPublicFolder() {
154-
fs.copySync(paths.appPublic, paths.appBuild, {
155-
dereference: true,
156-
filter: file => file !== paths.appHtml,
157-
});
158-
}

0 commit comments

Comments
 (0)