Skip to content

Instantly share code, notes, and snippets.

@japboy
Last active April 15, 2022 12:19
Show Gist options
  • Select an option

  • Save japboy/d69f3737dbc56508ca4da6233c3e63fe to your computer and use it in GitHub Desktop.

Select an option

Save japboy/d69f3737dbc56508ca4da6233c3e63fe to your computer and use it in GitHub Desktop.

Revisions

  1. japboy revised this gist Nov 7, 2017. No changes.
  2. japboy revised this gist Nov 7, 2017. 11 changed files with 273 additions and 1 deletion.
    22 changes: 22 additions & 0 deletions .babelrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    {
    "presets": [
    "stage-2",
    [
    "env", {
    "modules": false,
    "targets": {
    "browsers": [
    "Chrome >= 50",
    "ChromeAndroid >= 50",
    "Edge >= 12",
    "Explorer >= 11",
    "Firefox >= 40",
    "FirefoxAndroid >= 40",
    "iOS >= 7",
    "Safari >= 6"
    ]
    }
    }
    ]
    ]
    }
    16 changes: 16 additions & 0 deletions entry-a.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import _ from 'underscore';
    import Vue from 'vue';

    console.log(_.VERSION);
    console.log(Vue.version);

    async function test() {
    const response = await new Promise((resolve) => {
    setTimeout(() => {
    resolve('Hello.');
    }, 3000);
    });
    console.log(response);
    }

    test();
    16 changes: 16 additions & 0 deletions entry-b.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import _ from 'underscore';

    import 'babel-polyfill';

    console.log(_.VERSION);

    async function test() {
    const response = await new Promise((resolve) => {
    setTimeout(() => {
    resolve('Hello.');
    }, 3000);
    });
    console.log(response);
    }

    test();
    3 changes: 3 additions & 0 deletions entry-c.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    import Vue from 'vue';

    console.log(Vue.version);
    12 changes: 12 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>sample</title>
    <link rel="stylesheet" href="vendor.bundle.css">
    <script src="vendor.bundle.js" defer></script>
    <script src="entry-a.bundle.js" defer></script>
    </head>
    <body>
    </body>
    </html>
    6 changes: 6 additions & 0 deletions mod-a.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    import _ from 'underscore';

    export default function a() {
    console.log(_.VERSION);
    return 'a';
    }
    6 changes: 6 additions & 0 deletions mod-b.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    import Vue from 'vue';

    export default function b() {
    console.log(Vue.version);
    return 'b';
    }
    4 changes: 4 additions & 0 deletions mod-c.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@

    export default function c() {
    return 'c';
    }
    33 changes: 32 additions & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1 +1,32 @@
    {}
    {
    "name": "webpack-dll-testing",
    "version": "1.0.0",
    "scripts": {
    "start": "webpack --bail --config ./webpack.vendor.config.js && webpack --bail --config ./webpack.main.config.js",
    "test": "echo \"Error: no test specified\" && exit 1"
    },
    "license": "UNLICENSED",
    "private": true,
    "engines": {
    "node": "^8.9.0",
    "npm": "^5.5.1",
    "yarn": "^1.2.1"
    },
    "dependencies": {
    "babel-polyfill": "6.26.0",
    "normalize.css": "5.0.0",
    "underscore": "1.8.3",
    "vue": "2.3.3"
    },
    "devDependencies": {
    "babel-core": "6.26.0",
    "babel-loader": "7.1.2",
    "babel-preset-env": "1.6.0",
    "babel-preset-stage-2": "6.24.1",
    "css-loader": "0.28.7",
    "extract-text-webpack-plugin": "3.0.1",
    "happypack": "4.0.0",
    "style-loader": "0.19.0",
    "webpack": "3.6.0"
    }
    }
    77 changes: 77 additions & 0 deletions webpack.main.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    const os = require('os');
    const path = require('path');
    const webpack = require('webpack');
    const ExtractTextPlugin = require('extract-text-webpack-plugin');
    const HappyPack = require('happypack');

    const threadPoolCount = os.cpus().length;
    const happyThreadPool = HappyPack.ThreadPool({ size: threadPoolCount });

    const source = __dirname;
    const destination = __dirname;


    const VendorDllReference = new webpack.DllReferencePlugin({
    context: __dirname, // PROJECT ROOT WHERE NODE_MODULES ARE RELATIVELY RESOLVED!
    manifest: path.resolve(destination, 'vendor-manifest.json'),
    });

    const ExtractCSS = new ExtractTextPlugin({
    filename: '[name].bundle.css',
    allChunks: true,
    });

    module.exports = [
    {
    entry: {
    'entry-a': [
    'babel-polyfill', // Mutable library from vendor should be loaded explicitly
    './entry-a.js'
    ],
    'entry-b': './entry-b.js',
    'entry-c': './entry-c.js',
    },
    output: {
    filename: '[name].bundle.js',
    path: destination,
    publicPath: '/',
    },
    module: {
    rules: [
    {
    test: /\.css$/,
    loader: ExtractCSS.extract({
    fallback: 'style-loader',
    use: ['happypack/loader?id=css'],
    }),
    },
    {
    test: /\.js$/,
    loaders: ['happypack/loader?id=js'],
    },
    ],
    },
    plugins: [
    new HappyPack({
    id: 'css',
    threadPool: happyThreadPool,
    loaders: [
    {
    loader: 'css-loader',
    }
    ],
    }),
    new HappyPack({
    id: 'js',
    threadPool: happyThreadPool,
    loaders: [
    {
    loader: 'babel-loader',
    },
    ],
    }),
    VendorDllReference,
    ExtractCSS,
    ],
    }
    ];
    79 changes: 79 additions & 0 deletions webpack.vendor.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    const os = require('os');
    const path = require('path');
    const webpack = require('webpack');
    const ExtractTextPlugin = require('extract-text-webpack-plugin');
    const HappyPack = require('happypack');

    const threadPoolCount = os.cpus().length;
    const happyThreadPool = HappyPack.ThreadPool({ size: threadPoolCount });

    const source = __dirname;
    const destination = __dirname;


    const VendorDll = new webpack.DllPlugin({
    name: '[name]',
    path: path.resolve(destination, '[name]-manifest.json'),
    });

    const ExtractCSS = new ExtractTextPlugin({
    filename: '[name].bundle.css',
    allChunks: true,
    });

    module.exports = [
    {
    entry: {
    vendor: [
    'babel-polyfill',
    'underscore',
    'vue',
    'normalize.css',
    ],
    },
    output: {
    filename: '[name].bundle.js',
    library: '[name]',
    path: destination,
    publicPath: '/',
    },
    module: {
    rules: [
    {
    test: /\.css$/,
    loader: ExtractCSS.extract({
    fallback: 'style-loader',
    use: ['happypack/loader?id=css'],
    use: ['css-loader'],
    }),
    },
    {
    test: /\.js$/,
    loaders: ['happypack/loader?id=js'],
    },
    ],
    },
    plugins: [
    new HappyPack({
    id: 'css',
    threadPool: happyThreadPool,
    loaders: [
    {
    loader: 'css-loader',
    }
    ],
    }),
    new HappyPack({
    id: 'js',
    threadPool: happyThreadPool,
    loaders: [
    {
    loader: 'babel-loader',
    },
    ],
    }),
    VendorDll,
    ExtractCSS,
    ],
    },
    ];
  3. japboy created this gist Nov 7, 2017.
    1 change: 1 addition & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {}