cncjs
/
webpack.config.development.js
190 строк · 5.1 Кб
1const path = require('path');2const CSSSplitWebpackPlugin = require('css-split-webpack-plugin').default;3const dotenv = require('dotenv');4const HtmlWebpackPlugin = require('html-webpack-plugin');5const without = require('lodash/without');6const MiniCssExtractPlugin = require('mini-css-extract-plugin');7const nib = require('nib');8const stylusLoader = require('stylus-loader');9const webpack = require('webpack');10const ManifestPlugin = require('webpack-manifest-plugin');11const WriteFileWebpackPlugin = require('write-file-webpack-plugin');12const babelConfig = require('./babel.config');13const buildConfig = require('./build.config');14const pkg = require('./src/package.json');15
16dotenv.config();17
18const publicPath = process.env.PUBLIC_PATH || '';19const buildVersion = pkg.version;20const timestamp = new Date().getTime();21
22module.exports = {23mode: 'development',24cache: true,25target: 'web',26context: path.resolve(__dirname, 'src/app'),27devtool: 'cheap-module-eval-source-map',28entry: {29polyfill: [30path.resolve(__dirname, 'src/app/polyfill/index.js'),31'webpack-hot-middleware/client?path=/__webpack_hmr&reload=true',32],33app: [34path.resolve(__dirname, 'src/app/index.jsx'),35'webpack-hot-middleware/client?path=/__webpack_hmr&reload=true',36]37},38output: {39path: path.resolve(__dirname, 'output/cncjs/app'),40chunkFilename: `[name].[hash].bundle.js?_=${timestamp}`,41filename: `[name].[hash].bundle.js?_=${timestamp}`,42pathinfo: true,43publicPath: publicPath44},45module: {46rules: [47{48test: /\.jsx?$/,49loader: 'eslint-loader',50enforce: 'pre',51exclude: /node_modules/52},53{54test: /\.jsx?$/,55loader: 'babel-loader',56options: {57...babelConfig,58env: {59development: {60plugins: ['react-hot-loader/babel']61}62}63},64exclude: /node_modules/65},66{67test: /\.styl$/,68use: [69MiniCssExtractPlugin.loader,70{71loader: 'css-loader',72options: {73modules: true,74localIdentName: '[path][name]__[local]--[hash:base64:5]',75camelCase: true,76importLoaders: 177}78},79'stylus-loader'80],81exclude: [82path.resolve(__dirname, 'src/app/styles')83]84},85{86test: /\.styl$/,87use: [88MiniCssExtractPlugin.loader,89{90loader: 'css-loader',91options: {92modules: false,93camelCase: true,94}95},96'stylus-loader'97],98include: [99path.resolve(__dirname, 'src/app/styles')100]101},102{103test: /\.css$/,104use: [105'style-loader',106'css-loader'107]108},109{110test: /\.(png|jpg|svg)$/,111loader: 'url-loader',112options: {113limit: 8192114}115},116{117test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,118loader: 'url-loader',119options: {120limit: 10000,121mimetype: 'application/font-woff'122}123},124{125test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,126loader: 'file-loader'127}128]129},130node: {131fs: 'empty',132net: 'empty',133tls: 'empty'134},135plugins: [136new webpack.HotModuleReplacementPlugin(),137new webpack.DefinePlugin({138'process.env': {139NODE_ENV: JSON.stringify('development'),140BUILD_VERSION: JSON.stringify(buildVersion),141LANGUAGES: JSON.stringify(buildConfig.languages),142TRACKING_ID: JSON.stringify(buildConfig.analytics.trackingId)143}144}),145new webpack.LoaderOptionsPlugin({146debug: true147}),148new stylusLoader.OptionsPlugin({149default: {150// nib - CSS3 extensions for Stylus151use: [nib()],152// no need to have a '@import "nib"' in the stylesheet153import: ['~nib/lib/nib/index.styl']154}155}),156// https://github.com/gajus/write-file-webpack-plugin157// Forces webpack-dev-server to write bundle files to the file system.158new WriteFileWebpackPlugin(),159new webpack.ContextReplacementPlugin(160/moment[\/\\]locale$/,161new RegExp('^\./(' + without(buildConfig.languages, 'en').join('|') + ')$')162),163// Generates a manifest.json file in your root output directory with a mapping of all source file names to their corresponding output file.164new ManifestPlugin({165fileName: 'manifest.json'166}),167new MiniCssExtractPlugin({168filename: `[name].css?_=${timestamp}`,169chunkFilename: `[id].css?_=${timestamp}`170}),171new CSSSplitWebpackPlugin({172size: 4000,173imports: '[name].[ext]?[hash]',174filename: '[name]-[part].[ext]?[hash]',175preserve: false176}),177new HtmlWebpackPlugin({178filename: 'index.hbs',179template: path.resolve(__dirname, 'index.hbs'),180chunksSortMode: 'dependency' // Sort chunks by dependency181})182],183resolve: {184modules: [185path.resolve(__dirname, 'src'),186'node_modules'187],188extensions: ['.js', '.jsx']189}190};191