2
我試圖創建一個serviceworker塊(sw.js)與webpack2使用CommonsChunkPlugin
,但當試圖註冊/sw.js作爲服務人員時,我得到錯誤Uncaught ReferenceError: webpackJsonp is not defined
。ServiceManager與CommonsChunkPlugin塊不起作用,webpackJsonp沒有定義
顯然webpackJsonp是異步加載的塊,並搞亂我的serviceworker文件。無論如何刪除serviceworker塊的異步加載?
我的WebPack配置:
{
entry: {
main: [
'react-hot-loader/patch',
`webpack-dev-server/client?http://${host}:${port}`,
'webpack/hot/only-dev-server',
'./index.jsx',
],
sw: './sw.js',
vendor: [...],
},
output: {
filename: '[name].js',
path: resolve(__dirname, 'dist'),
publicPath: '/',
},
resolve: { extensions: ['.js', '.jsx'] },
performance: { hints: false },
context: resolve(__dirname, 'src'),
devtool: 'inline-source-map',
devServer: {
hot: true,
host,
port,
contentBase: resolve(__dirname, 'dist'),
publicPath: '/',
},
module: {
rules: [
{
test: /\.jsx?$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('css-loader'),
},
],
},
plugins: [
new ExtractTextPlugin('main.css'),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest'],
}),
],
};