Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Path = require('path');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const Webpack = require('webpack');
- const ExtractTextPlugin = require('extract-text-webpack-plugin');
- const CopyWebpackPlugin = require('copy-webpack-plugin');
- module.exports = (options) => {
- const ExtractSASS = new ExtractTextPlugin(`/styles/${options.cssFileName}`);
- const webpackConfig = {
- devtool: options.devtool,
- entry: [
- `webpack-dev-server/client?http://localhost:${+options.port}`,
- 'webpack/hot/dev-server',
- Path.join(__dirname, '../src/app/index'),
- ],
- output: {
- path: Path.join(__dirname, '../dist'),
- filename: `/scripts/${options.jsFileName}`,
- },
- resolve: {
- extensions: ['', '.js', '.jsx', '.css'],
- },
- module: {
- loaders: [
- {
- test: /.jsx?$/,
- include: Path.join(__dirname, '../src/app'),
- loader: 'babel',
- },
- {
- test: /\.css$/,
- include: [Path.resolve(__dirname, 'not_exist_path')],
- loader: ['style-loader', 'css-loader'],
- },
- ],
- },
- plugins: [
- new Webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development'),
- },
- }),
- new HtmlWebpackPlugin(
- {
- template: Path.join(__dirname, '../src/index.html'),
- },
- new CopyWebpackPlugin([
- {
- from: '../static/',
- to: 'static',
- },
- ])
- ),
- ],
- };
- if (options.isProduction) {
- webpackConfig.entry = [Path.join(__dirname, '../src/app/index')];
- webpackConfig.plugins.push(
- new Webpack.optimize.OccurenceOrderPlugin(),
- new Webpack.optimize.UglifyJsPlugin({
- compressor: {
- warnings: false,
- },
- }),
- ExtractSASS
- );
- webpackConfig.module.loaders.push({
- test: /\.scss$/,
- loader: ExtractSASS.extract(['css', 'sass']),
- });
- } else {
- webpackConfig.plugins.push(new Webpack.HotModuleReplacementPlugin());
- webpackConfig.module.loaders.push({
- test: /\.scss$/,
- loaders: ['style', 'css', 'sass'],
- });
- webpackConfig.module.loaders.push({
- test: /\.css$/,
- include: /node_modules/,
- loaders: ['style-loader', 'css-loader'],
- });
- webpackConfig.devServer = {
- contentBase: Path.join(__dirname, '../'),
- hot: true,
- port: options.port,
- inline: true,
- progress: true,
- historyApiFallback: true,
- stats: 'errors-only',
- disableHostCheck: true,
- proxy: {
- '/api': 'http://localhost:4000',
- },
- allowedHosts: ['.amazonaws.com'],
- };
- }
- return webpackConfig;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement