2017-04-18 117 views
0

我正试图在DLL之后放入一堆库文件,例如react-boilerplatethis one未定义Webpack dll导入

当我构建并运行DLL文件时给出的是未定义的。 我可能失去了一些东西我做了一个分开的WebPack打造的DLL:

import webpack from 'webpack' 
const library = '[name]' 
export default { 
    entry: { 
    'lokka': ['lokka', 'lokka-transport-http', 'socket.io-client'] 
    /** Other libs **/ 
    }, 
    output: { 
    filename: '[name].dll.js', 
    path: 'build/', 
    library: library 
    }, 
    plugins: [ 
    new webpack.DllPlugin({ 
     path: 'build/[name]-manifest.json', 
     name: library 
    }) 
    ] 
} 

,并添加到manifest.json的

import webpack from 'webpack' 
const desiredLibs = [ 
    'lokka' 
] 
const plugins = desiredLibs.map((lib) => { 
    return new webpack.DllReferencePlugin({ 
    context: process.cwd(), 
    manifest: require(`../build/${lib}-manifest.json`) 
    }) 
}) 
export const dllReference =() => { 
    return { plugins } 
} 
export default dllReference 

的引用是否有别的我应该怎么办?

在我的情况下,它抱怨代码运行时找不到lokka。

回答

0

原来我(明显)需要包括生成的DLL在我的脚本src和复制它的情况下dev,因为热重新加载只会服务于它的条目和它的依赖关系,所以对于dllReference和复制部分它变成:

import webpack from 'webpack' 
import CopyWebpackPlugin from 'copy-webpack-plugin' 
import path from 'path' 

const desiredLibs = ['lokka', 'react', 'moment'] 
const copies = [] 
const plugins = desiredLibs.map((lib) => { 
    copies.push({ 
    from: path.join(__dirname, `../compileResources/${lib}.dll.js`), 
    to: `dll` 
    }) 
    return new webpack.DllReferencePlugin({ 
    context: process.cwd(), 
    manifest: require(`../compileResources/${lib}-manifest.json`) 
    }) 
}) 
plugins.push(
    new CopyWebpackPlugin(copies) 
) 
/** 
* Adds the dll references and copies the file 
*/ 
export const dllReference =() => { 
    return { plugins } 
} 
export default dllReference 

然后,因为我复制了dll的使用复制插件,我需要在html上添加脚本。事后真的很明显