Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createApp(options) {
var app = express();
app.use(utils.timings);
app.use(helmet());
app.use(compression());
app.use(utils.rewritePath);
app.use(
express.static(hopsConfig.buildDir, {
maxAge: '1y',
setHeaders: function(res, filepath) {
if (mime.getType(filepath) === 'text/html' || filepath.match(swRe)) {
helmet.noCache()(null, res, function() {});
}
},
redirect: false,
})
);
utils.bootstrap(app, hopsConfig);
if (options && !options.static) {
var filePath = path.join(hopsConfig.cacheDir, 'server.js');
if (fs.existsSync(filePath)) {
utils.registerMiddleware(app.use(helmet.noCache()), require(filePath));
} else {
console.log(
return new Promise(function(resolve, reject) {
var filename = getFileName(location);
console.log(
filename.replace(hopsConfig.buildDir, ''),
filesize(Buffer.byteLength(html))
);
mkdirp(path.dirname(filename), function(err) {
if (err) {
reject(err);
} else {
fs.writeFile(filename, html, function(err) {
err ? reject(err) : resolve();
});
}
});
});
}
var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
var ServiceWorkerPlugin = require('../plugins/service-worker');
var MiniCSSExtractPlugin = require('mini-css-extract-plugin');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin');
var hopsConfig = require('hops-config');
var getAssetPath = path.join.bind(path, hopsConfig.assetPath);
module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
bail: true,
entry: require.resolve('../shims/build'),
output: {
path: hopsConfig.buildDir,
publicPath: '/',
pathinfo: true,
filename: getAssetPath('[name]-[chunkhash:16].js'),
chunkFilename: getAssetPath('[name]-[chunkhash:16].js'),
devtoolModuleFilenameTemplate: function(info) {
return path
.relative(hopsConfig.appDir, info.absoluteResourcePath)
.replace(/\\/g, '/');
},
},
context: hopsConfig.appDir,
resolve: require('../sections/resolve')('build'),
module: {
rules: require('../sections/module-rules')('build'),
},
devtool: 'source-map',
var webpack = require('webpack');
var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
var ServiceWorkerPlugin = require('../plugins/service-worker');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var hopsConfig = require('hops-config');
var getAssetPath = path.join.bind(path, hopsConfig.assetPath);
module.exports = {
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
bail: true,
entry: require.resolve('../shims/build'),
output: {
path: hopsConfig.buildDir,
publicPath: '/',
pathinfo: true,
filename: getAssetPath('[name]-[chunkhash:16].js'),
chunkFilename: getAssetPath('[name]-[chunkhash:16].js'),
devtoolModuleFilenameTemplate: function(info) {
return path
.relative(hopsConfig.appDir, info.absoluteResourcePath)
.replace(/\\/g, '/');
},
},
context: hopsConfig.appDir,
resolve: require('../sections/resolve')('build'),
module: {
rules: require('../sections/module-rules')('build'),
},
devtool: 'source-map',
var webpack = require('webpack');
var ServiceWorkerPlugin = require('../plugins/service-worker');
var hopsConfig = require('hops-config');
var getAssetPath = path.join.bind(path, hopsConfig.assetPath);
module.exports = {
mode: 'development',
entry: [
require.resolve('webpack-hot-middleware/client'),
require.resolve('../shims/develop'),
],
output: {
path: hopsConfig.buildDir,
publicPath: '/',
pathinfo: true,
filename: getAssetPath('[name].js'),
chunkFilename: getAssetPath('chunk-[id].js'),
devtoolModuleFilenameTemplate: function(info) {
return path.resolve(info.absoluteResourcePath).replace(/\\/g, '/');
},
},
context: hopsConfig.appDir,
resolve: require('../sections/resolve')('develop'),
module: {
rules: require('../sections/module-rules')('develop'),
},
plugins: [
new ServiceWorkerPlugin(),
new webpack.HotModuleReplacementPlugin(),
function getStatsFromFile() {
if (!stats) {
var statsFilename = path.join(hopsConfig.buildDir, 'stats.json');
if (fs.existsSync(statsFilename)) {
stats = require(statsFilename);
}
}
return stats || {};
}
function runDevelop(options, callback) {
var compiler = webpack(developConfig);
var app = express();
app.use(hopsExpressUtils.timings);
app.use(
webpackDevMiddleware(compiler, {
noInfo: true,
logLevel: 'warn',
publicPath: developConfig.output.publicPath,
watchOptions: developConfig.watchOptions,
serverSideRender: true,
})
);
app.use(webpackHotMiddleware(compiler));
app.use(hopsExpressUtils.rewritePath);
app.use(express.static(hopsConfig.buildDir, { redirect: false }));
hopsExpressUtils.bootstrap(app, hopsConfig);
hopsExpressUtils.registerMiddleware(
app,
createMiddleware(
nodeConfig,
nodeConfig.watchOptions || developConfig.watchOptions
)
);
hopsExpressUtils.teardown(app, hopsConfig);
hopsExpressUtils.run(app, callback);
}