Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable no-param-reassign */
config.entry = ["webpack-hot-middleware/client"].concat(config.entry)
config.output.filename = config.output.filename.replace("[chunkhash]", "[hash]")
config.output.chunkFilename = config.output.chunkFilename.replace("[chunkhash]", "[hash]")
config.plugins.push(new webpack.HotModuleReplacementPlugin())
config.plugins.push(new webpack.NoEmitOnErrorsPlugin())
config.plugins.push(new DashboardPlugin())
})
// For other settings see
// https://webpack.github.io/docs/webpack-dev-middleware
let bundler
try {
bundler = webpack(webpackConfig)
} catch (e) {
console.error(e)
}
const wpMiddleware = webpackMiddleware(bundler, {
publicPath: webpackConfig[0].output.publicPath,
stats: webpackConfig[0].stats
})
const hotMiddlewares = bundler.compilers
.filter(compiler => compiler.options.target !== "node")
.map(compiler => webpackHotMiddleware(compiler))
let handleServerBundleComplete = () => {
runServer((err, host) => {
if (!err) {
hook.compiler.run(hook.afterBuild.bind(hook));
}
});
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development' && config.server) {
const WebpackDevServer = require('webpack-dev-server');
const defaultDevServerConfig = {
hot: true,
port: 3000,
};
// merge defaults
config.server.config = Object.assign(defaultDevServerConfig, config.server.config || {});
if (config.server.webpack) {
hook.devServerCompiler = webpack(config.server.webpack);
}
hook.devServer = new WebpackDevServer(
hook.devServerCompiler || hook.compiler,
config.server.config
);
hook.devServer.listen(config.server.config.port);
}
return hook;
}
_newCompiler() {
const compiler = webpack(WebpackConfig.theOne.webpackConfig);
// We use a `memory_fs` to hold the immediate results of compilation, to
// make it possible to detect when things go awry before anything gets
// cached or (heaven forfend) sent out over the network. Once a compilation
// is successful, we grab the result into `_currentBundles` and erase it
// from the memory FS.
compiler.outputFileSystem = this._fs;
return compiler;
}
/* eslint import/no-extraneous-dependencies: "off" */
import webpack from 'webpack';
import Hapi from 'hapi';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import webpackConfig from './webpack.config.development';
import logger from '../src/server/logger';
const compiler = webpack(webpackConfig);
const host = 'localhost';
const port = 3001;
const serverOptions = {
contentBase: `http://${host}:${port}`,
quiet: false,
noInfo: false,
hot: true,
inline: true,
lazy: false,
publicPath: webpackConfig.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
stats: { colors: true },
};
const app = new Hapi.Server();
const devMiddleware = webpackDevMiddleware(compiler, serverOptions);
/* eslint no-var: 0, no-console: 0 */
import webpack from 'webpack'
import WebpackDevServer from 'webpack-dev-server'
import webpackConfig from './webpack.client.rails.hot.config'
const hotRailsPort = process.env.HOT_RAILS_PORT || 3500
const compiler = webpack(webpackConfig)
const devServer = new WebpackDevServer(compiler, {
contentBase: 'http://lvh.me:' + hotRailsPort,
publicPath: webpackConfig.output.publicPath,
headers: { 'Access-Control-Allow-Origin': '*' },
hot: true,
inline: true,
historyApiFallback: true,
quiet: false,
noInfo: false,
lazy: false,
stats: {
colors: true,
hash: false,
version: false,
chunks: false,
query: {
presets: [],
},
},
],
},
plugins: [
new webpack.EnvironmentPlugin(['NODE_ENV', 'DEBUG']),
new webpack.EnvironmentPlugin({
NODE_ENV: 'development',
DEBUG: false
}),
],
};
webpack(options, function(err: WebpackError, stats: Stats) {
if (err) {
console.error(err.stack || err);
if (err.details) {
console.error(err.details);
}
return;
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors);
}
if (stats.hasWarnings()) {
console.warn(info.warnings);
if (options.watchOptions) {
devServerConfig.watchOptions = options.watchOptions;
}
if (options.devServerProxy) {
devServerConfig.proxy = options.devServerProxy;
}
if (options.devServer) {
deepAssign(devServerConfig, options.devServer);
}
if (options.webpackProfile) config.profile = true;
const compiler = webpack(config);
if (options.webpackProfile) {
compiler.plugin('done', stats => {
const profileFile = path.resolve(options.webpackProfile);
const statsString = JSON.stringify(stats.toJson());
writeFile(profileFile, statsString, (err) => {
if (err) return console.error('Failed to write webpackProfile:', err);
console.log('[webpack] Wrote webpack stats to:', profileFile);
console.log('[webpack] Analyze stats at https://webpack.github.io/analyse/');
});
});
}
const server = new WebpackDevServer(compiler, devServerConfig);
server.use('/', (req, res, next) => {
return new Promise((resolve, reject) => {
const compiler = webpack(webpackClient);
const server = new WebpackDevServer(compiler, {
contentBase: buildPath,
hot: true,
publicPath: '/',
stats,
historyApiFallback: {
index: '/',
},
});
compiler.run(err => {
try {
if (err) throw err;
server.listen(DEV_PORT, DEV_HOSTNAME, err2 => {
if (err2) throw reject(err2);
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
unused: true,
dead_code: true,
warnings: false,
screw_ie8: true
},
output: {
comments: false
}
})
]
}, CommonConfig)
return webpack(ProductionDebugConfig).run((error, stats) => {
if (error) {
return rejec(error)
}
return webpack(ProductionMinifiedConfig).run((error, stats) => {
if (error) {
return reject(error)
}
return resolve()
})
})
})
}