somewind / amd-webpack-plugin

make split chunks be AMD modules
MIT License
4 stars 1 forks source link

template.getAssetPath is not a function #1

Closed mfreeman-xtivia closed 5 years ago

mfreeman-xtivia commented 5 years ago

Trying to use the plugin on below webpack config file. It generates the main chunk file just fine and then throws this function when attempting to process the vendor file. This appears to be some kind of issue at line 39 of lib/wrapper.js:

const realName = template.getAssetPath(name, {


const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const AmdWebpackPlugin = require('amd-webpack-plugin');

module.exports = {
    mode: "development",
    bail: true,

  optimization: {
    splitChunks: {
      chunks: 'all',
      cacheGroups: {
        default: false,
        vendors: false,
        // choose other node_modules to be vendor.js
        vendor: {
          name: 'vendor',
          chunks: 'all',
          minChunks: 1,
          test: /[\\/]node_modules[\\/]/,
          priority: 10
        }
      }
    }
  },
    context: path.join(__dirname, "src"),
    entry: {
        app: "./index.js",
    },
    output: {
        library: "[name]",
        libraryTarget: 'amd',
        libraryExport: 'default',
        filename: "app.[contenthash].js",
        path: path.join(__dirname,"build"),
        devtoolModuleFilenameTemplate: '[resource-_path]',
    },
    plugins: [

    new AmdWebpackPlugin({wrapper: 'Liferay.Loader.define' }),
        new CleanWebpackPlugin({verbose: true, dry: false})
    ],
    module: {
        rules: [
            {
                test: /\.(js|jsx)$/i,
                use: 'babel-loader',
                exclude: /node_modules/
            }
        ]
    },
    resolve: {
        extensions: [".jsx", ".js"]
    }
}
mfreeman-xtivia commented 5 years ago

I wonder if someone could at least tell me what the template object is supposed to represent at this point?

At the point of the errors it has keys=["_pluginCompat","outputOptions","hooks"] which at least explains the error. Is this an object that changed from Webpack 3 to Webpack 4?

somewind commented 5 years ago

Sorry for the late reply, I should have seen it earlier.

What's your webpack version?

I haven't tested the lower version of webpack 4, so maybe it's not compatible here. In my use, webpack version is ^4.26.1.

mfreeman-xtivia commented 5 years ago

My version of webpack is 4.29.6

Reproducible on demand using the example webpack config

somewind commented 5 years ago

Your output.library config caused this bug, which can not working in SplitChunk.

I have released version 1.0.17 to be compatible with output.library, please have a try.