2017-06-21 14 views
2

私はちょうどこのguide非同期コード分割のWebPACK - 予期しないトークン

を以下ました、私はこのコードを持っている:

import React, { PropTypes, Component } from 'react'; 

import('contact-page').then(() => {}); 

を、私はこの出力を得る: webpack output

これは私のWebPACKファイルです:

var webpack = require('webpack'); 
var packages = require('./package.json'); 
var path = require('path'); 

var ExtractTextPlugin = require("extract-text-webpack-plugin"); 
var HtmlWebpackPlugin = require('html-webpack-plugin'); 

var filterDependencies = ['normalize.css', 'font-awesome']; 
var dependencies = Object.keys(packages.dependencies).filter(f => !filterDependencies.some(fd => fd === f)); 


module.exports = { 
    entry: { 
     main: './src/index.js', 
     vendor: dependencies 
    }, 
    output: { 
     filename: '[name].js', 
     path: path.resolve(__dirname, 'dist') 
    }, 

    plugins: [ 
     new webpack.optimize.CommonsChunkPlugin({ 
      name: "vendor", 
      minChunks: Infinity, 
     }), 
     new ExtractTextPlugin("styles.css"), 
     new HtmlWebpackPlugin({ 
      template: 'index.html' 
     }) 
    ], 

    module: { 
     rules: [ 
      { 
       test: /\.js?$/, 
       use: [ 'babel-loader', ], 
       exclude: /node_modules/ 
      }, 
      { 
       test: /\.css$/, 
       use: ExtractTextPlugin.extract({ 
        fallback: "style-loader", 
        use: "css-loader" 
       }), 
       exclude: /node_modules/ 
      }, 
      { 
       test: /(\.png|\.jpg|\.otf)$/, 
       use: ['file-loader?name=[name].[ext]&publicPath=assets/&outputPath=assets/'] 
      } 
     ] 
    }, 

    performance: { 
     hints: "warning", // enum 
     maxAssetSize: 200000, // int (in bytes), 
     maxEntrypointSize: 400000, // int (in bytes) 
     assetFilter: function (assetFilename) { 
      // Function predicate that provides asset filenames 
      return assetFilename.endsWith('.css') || assetFilename.endsWith('.js'); 
     } 
    }, 

    devtool: "source-map", // enum 

    target: "web", // enum 

    stats: "errors-only", 

    devServer: { 
     proxy: { // proxy URLs to backend development server 
      '/api': 'http://localhost:3000' 
     }, 
     contentBase: path.join(__dirname, 'public'), // boolean | string | array, static file location 
     compress: true, // enable gzip compression 
     historyApiFallback: true, // true for index.html upon 404, object for multiple paths 
     hot: true, // hot module replacement. Depends on HotModuleReplacementPlugin 
     https: false, // true for self-signed, object for cert authority 
     noInfo: true, // only errors & warns on hot reload 
     // ... 
    } 
}; 

答えて

3

ダイナミン輸入の場合babel-plugin-syntax-dynamic-importライブラリ使用して - あなたは(限り、あなたはes2015をミックスしたいと反応して)のようなものにmodule.rulesセットを拡張する必要がインストールした後https://www.npmjs.com/package/babel-plugin-syntax-dynamic-import

を:

module: { 
    rules: [ 
    { 
    test: /\.js?$/, 
    use: { 
     loader: 'babel-loader', 
     options: { 
     presets: [['es2015', "react"]], 
     plugins: ['syntax-dynamic-import'] 
     }, 
    }, 
    exclude: /node_modules/ 
    }, 
}, 

それは、より詳細なチュートリアルhttps://webpack.js.org/guides/code-splitting-async/#usage-with-babelに記載されています。

+0

私は明らかにそれを逃しました..... –

+0

'babel-plugin-syntax-dynamic-import'は[email protected]で助けになりません –

関連する問題