Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dipiash
Created March 21, 2018 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dipiash/ba1df7336db73826d511a4e47f7ffc54 to your computer and use it in GitHub Desktop.
Save dipiash/ba1df7336db73826d511a4e47f7ffc54 to your computer and use it in GitHub Desktop.
Moment optimisation
const path = require('path');
const glob = require('glob');
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
const {ANALYZE} = process.env;
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
module.exports = {
webpack: (config, {dev, isServer}) => {
if (ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerPort: isServer ? 8888 : 8889,
openAnalyzer: true
}));
}
config.module.rules.push(
{
test: /\.(css|scss)/,
loader: 'emit-file-loader',
options: {
name: 'dist/[path][name].[ext]'
}
},
{
test: /\.css$/,
use: ['babel-loader', 'raw-loader', 'postcss-loader']
},
{
test: /\.s(a|c)ss$/,
use: ['babel-loader', 'raw-loader', 'postcss-loader',
{
loader: 'sass-loader',
options: {
includePaths: ['styles', 'node_modules']
.map(d => path.join(__dirname, d))
.map(g => glob.sync(g))
.reduce((a, c) => a.concat(c), [])
}
}
]
}
);
config.plugins.push(new MomentLocalesPlugin({
localesToKeep: ['ru'],
}));
return config;
},
};
module.exports = {
plugins: [
require('postcss-easy-import')({prefix: '_'}), // keep this first
require('autoprefixer')({ /* ...options */ }), // so imports are auto-prefixed too
require('cssnano')()
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment