123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- const webpack = require('webpack')
- const path = require('path')
- const fs = require('fs-extra')
- const yargs = require('yargs').argv
- const _ = require('lodash')
- const { VueLoaderPlugin } = require('vue-loader')
- const CopyWebpackPlugin = require('copy-webpack-plugin')
- const HtmlWebpackPlugin = require('html-webpack-plugin')
- const HtmlWebpackPugPlugin = require('html-webpack-pug-plugin')
- const MomentTimezoneDataPlugin = require('moment-timezone-data-webpack-plugin')
- const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
- const WriteFilePlugin = require('write-file-webpack-plugin')
- const WebpackBarPlugin = require('webpackbar')
- const babelConfig = fs.readJsonSync(path.join(process.cwd(), '.babelrc'))
- const cacheDir = '.webpack-cache/cache'
- const babelDir = path.join(process.cwd(), '.webpack-cache/babel')
- process.noDeprecation = true
- fs.emptyDirSync(path.join(process.cwd(), 'assets'))
- module.exports = {
- mode: 'development',
- entry: {
- app: ['./client/index-app.js', 'webpack-hot-middleware/client'],
- legacy: ['./client/index-legacy.js', 'webpack-hot-middleware/client'],
- setup: ['./client/index-setup.js', 'webpack-hot-middleware/client']
- },
- output: {
- path: path.join(process.cwd(), 'assets'),
- publicPath: '/_assets/',
- filename: 'js/[name].js',
- chunkFilename: 'js/[name].js',
- globalObject: 'this',
- pathinfo: true,
- crossOriginLoading: 'use-credentials'
- },
- module: {
- rules: [
- {
- test: /\.js$/,
- exclude: (modulePath) => {
- return modulePath.includes('node_modules') && !modulePath.includes('vuetify')
- },
- use: [
- {
- loader: 'cache-loader',
- options: {
- cacheDirectory: cacheDir
- }
- },
- {
- loader: 'babel-loader',
- options: {
- ...babelConfig,
- cacheDirectory: babelDir
- }
- }
- ]
- },
- {
- test: /\.css$/,
- use: [
- 'style-loader',
- 'css-loader',
- 'postcss-loader'
- ]
- },
- {
- test: /\.sass$/,
- use: [
- {
- loader: 'cache-loader',
- options: {
- cacheDirectory: cacheDir
- }
- },
- 'style-loader',
- 'css-loader',
- 'postcss-loader',
- {
- loader: 'sass-loader',
- options: {
- implementation: require('sass'),
- sourceMap: false,
- sassOptions: {
- fiber: false
- }
- }
- }
- ]
- },
- {
- test: /\.scss$/,
- use: [
- {
- loader: 'cache-loader',
- options: {
- cacheDirectory: cacheDir
- }
- },
- 'style-loader',
- 'css-loader',
- 'postcss-loader',
- {
- loader: 'sass-loader',
- options: {
- implementation: require('sass'),
- sourceMap: false,
- sassOptions: {
- fiber: false
- }
- }
- },
- {
- loader: 'sass-resources-loader',
- options: {
- resources: path.join(process.cwd(), '/client/scss/global.scss')
- }
- }
- ]
- },
- {
- test: /\.vue$/,
- loader: 'vue-loader'
- },
- {
- test: /\.pug$/,
- exclude: [
- path.join(process.cwd(), 'dev')
- ],
- loader: 'pug-plain-loader'
- },
- {
- test: /\.(png|jpg|gif)$/,
- use: [
- {
- loader: 'url-loader',
- options: {
- limit: 8192
- }
- }
- ]
- },
- {
- test: /\.svg$/,
- exclude: [
- path.join(process.cwd(), 'node_modules/grapesjs')
- ],
- use: [
- {
- loader: 'file-loader',
- options: {
- name: '[name].[ext]',
- outputPath: 'svg/'
- }
- }
- ]
- },
- {
- test: /\.(graphql|gql)$/,
- exclude: /node_modules/,
- use: [
- { loader: 'graphql-persisted-document-loader' },
- { loader: 'graphql-tag/loader' }
- ]
- },
- {
- test: /\.(woff2|woff|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
- use: [{
- loader: 'file-loader',
- options: {
- name: '[name].[ext]',
- outputPath: 'fonts/'
- }
- }]
- },
- {
- loader: 'webpack-modernizr-loader',
- test: /\.modernizrrc\.js$/
- }
- ]
- },
- plugins: [
- new VueLoaderPlugin(),
- new VuetifyLoaderPlugin(),
- new MomentTimezoneDataPlugin({
- startYear: 2017,
- endYear: (new Date().getFullYear()) + 5
- }),
- new CopyWebpackPlugin({
- patterns: [
- { from: 'client/static' },
- { from: './node_modules/prismjs/components', to: 'js/prism' }
- ]
- }),
- new HtmlWebpackPlugin({
- template: 'dev/templates/master.pug',
- filename: '../server/views/master.pug',
- hash: false,
- inject: false,
- excludeChunks: ['setup', 'legacy']
- }),
- new HtmlWebpackPlugin({
- template: 'dev/templates/legacy.pug',
- filename: '../server/views/legacy/master.pug',
- hash: false,
- inject: false,
- excludeChunks: ['setup', 'app']
- }),
- new HtmlWebpackPlugin({
- template: 'dev/templates/setup.pug',
- filename: '../server/views/setup.pug',
- hash: false,
- inject: false,
- excludeChunks: ['app', 'legacy']
- }),
- new HtmlWebpackPugPlugin(),
- new WebpackBarPlugin({
- name: 'Client Assets'
- }),
- new webpack.DefinePlugin({
- 'process.env.NODE_ENV': JSON.stringify('development'),
- 'process.env.CURRENT_THEME': JSON.stringify(_.defaultTo(yargs.theme, 'default'))
- }),
- new WriteFilePlugin(),
- new webpack.HotModuleReplacementPlugin(),
- new webpack.WatchIgnorePlugin([
- /node_modules/
- ])
- ],
- optimization: {
- namedModules: true,
- namedChunks: true,
- splitChunks: {
- cacheGroups: {
- default: {
- minChunks: 2,
- priority: -20,
- reuseExistingChunk: true
- },
- vendor: {
- test: /[\\/]node_modules[\\/]/,
- minChunks: 2,
- priority: -10
- }
- }
- },
- runtimeChunk: 'single'
- },
- resolve: {
- mainFields: ['browser', 'main', 'module'],
- symlinks: true,
- alias: {
- '@': path.join(process.cwd(), 'client'),
- 'vue$': 'vue/dist/vue.esm.js',
- 'gql': path.join(process.cwd(), 'client/graph'),
- // Duplicates fixes:
- 'apollo-link': path.join(process.cwd(), 'node_modules/apollo-link'),
- 'apollo-utilities': path.join(process.cwd(), 'node_modules/apollo-utilities'),
- 'uc.micro': path.join(process.cwd(), 'node_modules/uc.micro'),
- 'modernizr$': path.resolve(process.cwd(), 'client/.modernizrrc.js')
- },
- extensions: [
- '.js',
- '.json',
- '.vue'
- ],
- modules: [
- 'node_modules'
- ]
- },
- node: {
- fs: 'empty'
- },
- stats: {
- children: false,
- entrypoints: false
- },
- target: 'web',
- watch: true
- }
|