docs icon indicating copy to clipboard operation
docs copied to clipboard

can DllPlugin and DllReferencePlugin run in browser by use the style of 'commonjs2' instead of 'insert a script tag in html' ?

Open klouskingsley opened this issue 9 years ago • 2 comments

I try to use commonjs2 style in DllPlugin and the browser return an error

Uncaught ReferenceError: require is not defined

here is my config files

  • webpack dll config
var webpack = require('webpack')

module.exports = {
    output: {
        path: './dll',
        filename: '[name].js',
        library: '[name]',
        libraryTarget: 'commonjs2'
    },
    entry: {
        test: ['./js/lib/browser.js']
    },
    plugins: [
        new webpack.DllPlugin({
            path: './dll/[name]-manifest.json',
            name: '[name]',
            context: __dirname
        })
    ]
}
  • webpack config fle
var webpack = require('webpack')

module.exports = {
    output: {
        path: __dirname,
        filename: '[name].bundle.js',
    },
    entry: {
        app: ['./app.js']
    },
    plugins: [
        new webpack.DllReferencePlugin({
            manifest: require('./dll/test-manifest.json'),
            context: __dirname,
            sourceType: 'commonjs2',
            name: './dll/test.js'
        })
    ]
}

klouskingsley avatar Dec 21 '16 07:12 klouskingsley

Does somebody find solution here?

captain-yossarian avatar Aug 16 '18 09:08 captain-yossarian

I had the same error 🤔

yousefallaban avatar Mar 06 '19 21:03 yousefallaban