entria / entria-fullstack

Monorepo Playground with GraphQL, React, React Native, Relay Modern, TypeScript and Jest
MIT License
497 stars 73 forks source link

implement webpack dll #130

Closed sibelius closed 8 months ago

sibelius commented 4 years ago

for web package https://github.com/entria/entria-fullstack/tree/master/packages/web

mauriciord commented 4 years ago

@sibelius

I hope it helps

//plugins.js
    new webpack.DllReferencePlugin({
      manifest: require(path.join(PATHS.ROOT_DIR, 'build/dll/vendors.json')),
    }),

// ###########################################################

// webpack.dll.config.js
const webpack = require('webpack');
const { PATHS, VENDORS_LIST } = require('./shared/constants');

const dllConfig = () => {
  const isProduction = process.env.NODE_ENV === 'production';
  return {
    context: PATHS.ROOT_DIR,
    entry: {
      vendors: VENDORS_LIST,
    },
    output: {
      library: '[name]',
      path: PATHS.STATIC_DLL,
      filename: isProduction ? '[name].[contenthash].dll.js' : '[name].dll.js',
    },
    mode: isProduction ? 'production' : 'development',
    plugins: [
      new webpack.DllPlugin({
        name: '[name]',
        path: 'build/dll/[name].json',
      }),
    ],
  };
};

module.exports = dllConfig;
// ###########################################################
"scripts": {
    "prestart": "rimraf build && NODE_ENV=development webpack --config scripts/webpack/webpack.dll.config.js",
    "start": "NODE_ENV=development webpack-dev-server --config scripts/webpack/webpack.config.js --progress",
    "predev": "rimraf build && NODE_ENV=development webpack --config scripts/webpack/webpack.dll.config.js",
    "dev": "NODE_ENV=development webpack --config scripts/webpack/webpack.config.js --progress",
    "prebuild": "rimraf build && NODE_ENV=production webpack --config scripts/webpack/webpack.dll.config.js",
    "build": " NODE_ENV=production webpack --config scripts/webpack/webpack.config.js",