Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function startServer() {
try {
const reporter = (...args) => webpackReporter(logBack, ...args);
if (__DEV__) {
_.each(serverConfig.entry, entry => {
if (__WINDOWS__) {
entry.push('webpack/hot/poll?1000');
} else {
entry.push('webpack/hot/signal.js');
}
});
serverConfig.plugins.push(new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin());
}
const compiler = webpack(serverConfig);
if (__DEV__) {
compiler.plugin('compilation', compilation => {
compilation.plugin('after-optimize-assets', assets => {
// Patch webpack-generated original source files path, by stripping hash after filename
const mapKey = _.findKey(assets, (v, k) => k.endsWith('.map'));
if (mapKey) {
var srcMap = JSON.parse(assets[mapKey]._value);
for (var idx in srcMap.sources) {
srcMap.sources[idx] = srcMap.sources[idx].split(';')[0];
}
assets[mapKey]._value = JSON.stringify(srcMap);
}
function getPlugins() {
var plugins = [];
// Always expose NODE_ENV to webpack, you can now use `process.env.NODE_ENV`
// inside your code for any environment checks; UglifyJS will automatically
// drop any unreachable code.
//plugins.push(new DefinePlugin({
// "process.env.NODE_ENV": "\"production\""
//}));
plugins.push(new NoEmitOnErrorsPlugin());
if(scripts.length > 0){
plugins.push(new ConcatPlugin({
"uglify": false,
"sourceMap": true,
"name": "scripts",
"fileName": "[name].bundle.js",
"filesToConcat": scripts
}));
plugins.push(new InsertConcatAssetsWebpackPlugin([
"scripts"
]));
}
plugins.push(new GlobCopyWebpackPlugin({
"patterns": [
module.exports = function setupDevServer(app, callback) {
let backend;
if (renderBackend) {
// modify client config to work with hot middleware
clientConfig.entry.admin = ['./build/dev-client', clientConfig.entry.admin]
clientConfig.output.filename = '[name].js'
clientConfig.plugins.push(new webpack.HotModuleReplacementPlugin(), new webpack.NoEmitOnErrorsPlugin())
// dev middleware
const clientCompiler = webpack(clientConfig)
const devMiddleware = require('webpack-dev-middleware')(clientCompiler, {
publicPath: clientConfig.output.publicPath,
noInfo: true
})
app.use(devMiddleware)
clientCompiler.plugin('done', () => {
const fs = devMiddleware.fileSystem
// 后台
let backendPath = path.join(clientConfig.output.path, 'admin.html')
if (fs.existsSync(backendPath)) {
backend = fs.readFileSync(backendPath, 'utf-8')
}
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
else if (use_hot_reload)
{
module.exports.entry.push('webpack-dev-server/client?http://' + dev_server_addr + ':' + dev_server_port);
module.exports.entry.push('webpack/hot/only-dev-server');
module.exports.output['publicPath'] = 'http://' + dev_server_addr + ':' + dev_server_port + dist_dir + '/';
module.exports.plugins.push(new webpack.HotModuleReplacementPlugin());
module.exports.plugins.push(new webpack.NoEmitOnErrorsPlugin()); // don't reload if there is an error
}
this._webpackHotOptions = webpackHotOptions;
const encodeHmrPath = encodeURIComponent(webpackHotOptions.path);
const hmrClient = [`webpack-hot-middleware/client?path=${encodeHmrPath}`];
if (typeof config.entry === "object") {
Object.keys(config.entry).forEach(k => {
config.entry[k] = hmrClient.concat(config.entry[k]);
});
} else {
config.entry = hmrClient.concat(config.entry);
}
config.plugins = [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
].concat(config.plugins);
const compiler = webpack(config);
if (options.progress !== false) {
compiler.apply(new webpack.ProgressPlugin({ profile: options.progressProfile }));
}
const webpackDevOptions = _.merge(
{
// https: false,
// disableHostCheck: true,
headers: {
"Access-Control-Allow-Origin": "*"
},
// port: archetype.webpack.devPort,
]
},
],
},
plugins: [
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env),
// TODO description
new webpack.LoaderOptionsPlugin({
debug,
minimize: !debug,
}),
// TODO description
new webpack.NoEmitOnErrorsPlugin(),
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
new ExtractTextPlugin(filename.css),
]
.concat(server ? [
// Watcher doesn't work well if you mistype casing in a path so we use
// a plugin that prints an error when you attempt to do this.
// See https://github.com/facebookincubator/create-react-app/issues/240
new CaseSensitivePathsPlugin(),
// If you require a missing module and then `npm install` it, you still have
// to restart the development server for Webpack to discover it. This plugin
// makes the discovery automatic so you don't have to restart.
// See https://github.com/facebookincubator/create-react-app/issues/186
new WatchMissingNodeModulesPlugin(source.nodeModulesPath),
] : [])
.concat(product ? [
// TODO comment
}),
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)@angular/,
root('./src')
),
new webpack.LoaderOptionsPlugin({
tslint: {
emitErrors: false,
failOnHint: false
}
})
];
if (isProd) {
config.plugins.push(
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.UglifyJsPlugin({sourceMap: true, mangle: { keep_fnames: true }}),
new CopyWebpackPlugin([{
from: root('public'),
to: 'public'
}])
);
}
if (!isTest) {
config.plugins.push(
new webpack.optimize.CommonsChunkPlugin({
name: ['vendor', 'polyfills']
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
chunksSortMode: 'dependency'
function getDevelopmentConfig() {
return {
devtool: 'inline-source-map',
module: {
rules: [
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] }
]
},
plugins: [
new webpack.EnvironmentPlugin({ 'NODE_ENV': 'development' }),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.optimize.CommonsChunkPlugin({
minChunks: Infinity,
name: 'inline'
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['app'],
minChunks: module => {
return module.resource && module.resource.startsWith(nodeModules)
}
})
]
};
}
new HtmlWebpackPlugin({
template: paths.client('index.html'),
hash: false,
filename: 'index.html',
inject: 'body',
minify: {
collapseWhitespace: true
}
})
];
if (__DEV__) {
debug('Enable plugins for live development (HMR, NoErrors).');
webpackConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
);
} else if (__PROD__) {
debug('Enable plugins for production (OccurenceOrder, Dedupe & UglifyJS).');
webpackConfig.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true,
conditionals: true,
unused: true,
comparisons: true,
];
const plugins = [
new DefinePlugin({
ENV: JSON.stringify(env)
}),
new webpack.DllReferencePlugin({
context: '.',
manifest: require('./web/vendor-manifest.json')
}),
];
if (env === 'dev') {
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new webpack.NamedModulesPlugin());
plugins.push(new webpack.NoEmitOnErrorsPlugin());
}
module.exports = {
cache: true,
mode: 'development',
entry: {
app: prod ? [entry] : [...hot, entry]
},
output: {
publicPath,
path: path.join(__dirname, prod ? 'dist' : 'web'),
filename: prod ? 'ruui.js' : '[name].bundle.js',
chunkFilename: '[name].js',
library: 'ruui',
libraryTarget: 'umd',
},