2017-08-22 69 views
0
entry: { 
    vender: [ 
     'react', 
     'react-dom', 
     'eslint-plugin-react', 
    ], 
}, 

上面的代碼片段似乎是我的問題的原因。此代碼示例是我的webpack.config.js文件的一部分。如果我爲這個應用程序運行yarn build,它將刪除我通過ExtractTextWebpackPlugin(我的代碼中的ETP)創建的CSS文件。如果我註釋掉上面的代碼部分,在運行構建之後,CSS文件出現在公共目錄中。有誰會碰巧知道我可以如何解決這個問題。Webpack中的供應商正在禁用我的CSS

const ETP = require('extract-text-webpack-plugin'); 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 
const merge = require('webpack-merge'); 
const OpenBrowserPlugin = require('open-browser-webpack-plugin'); 
const parts = require('./webpack.parts'); 
const path = require('path'); 
const webpack = require('webpack'); 
const glob = require('glob'); 

const PATHS = { 
    public: path.join(__dirname, 'public'), 
    src: path.join(__dirname, 'src'), 
    styles: path.join(__dirname, 'src', 'scss'), 
}; 

const options = { 
    host: 'localhost', 
    port: '8085', 
}; 

const commonConfig = merge([ 
    { 
    entry: PATHS.src, 
    output: { 
     path: PATHS.public, 
     filename: '[name].bundle.js', 
    }, 
    plugins: [ 
     new HtmlWebpackPlugin({ 
     title: 'Jason Ganz Portfolio', 
     template: path.join(PATHS.src, 'index.html'), 
     }), 
     new OpenBrowserPlugin({ 
     url: `http://${options.host}:${options.port}`, 
     }), 
     new ETP('style.css'), 
     new webpack.LoaderOptionsPlugin({ 
     options: { 
      eslint: { 
      failOnWarning: false, 
      failOnError: true, 
      fix: false, 

      //  // Output to Jenkins compatible XML 
      //  // outputReport: { 
      //  //  filePath: 'checkstyle.xml', 
      //  //  formatter: require('eslint/lib/formatters/checkstyle'), 
      //  // }, 
      }, 
     }, 
     }), 
     parts.purifyCSS({ 
     paths: glob.sync(`${PATHS.src}/**/*.js`, {nodir: true}), 
     }), 
    ], 
    }, 
    parts.loadSASS(PATHS.styles), 
    parts.loadJSX(), 


]); 

const productionConfig = merge([ 
    //Generates Source Maps for js files 
    parts.generateSourceMaps({ type: 'source-map' }), 
    { 
    entry: { 
     vender: [ 
     'react', 
     'react-dom', 
     'eslint-plugin-react', 
     ], 
    }, 
    plugins: [ new webpack.optimize.CommonsChunkPlugin({name: 'vendor'})], 
    }, 
]); 

const developmentConfig = merge([ 
    parts.devServer({ 
    host: options.host, 
    port: options.port, 
    path: PATHS.public, 
    }), 
    { 
    output: { 
     devtoolModuleFilenameTemplate: 'webpack:///[absolute-resource-path]', 
    }, 
    }, 
    parts.generateSourceMaps({ type: 'cheap-module-eval-source-map' }), 
]); 

module.exports = (env) => { 
    if(env == 'development') { 
    return merge(commonConfig, developmentConfig); 
    } 

    return merge(commonConfig, productionConfig); 
}; 

我的裝載機和模塊被存儲在下面可以看到一個單獨的webpack.parts.js文件。

const ETP = require('extract-text-webpack-plugin'); 
const PurifyCSSPlugin = require('purifycss-webpack'); 

exports.devServer = ({host, port, path} = {})=> ({ 
    devServer: { 
    compress: true, 
    contentBase: path, 
    historyApiFallback: true, 
    host, 
    port, 
    overlay: { 
     errors: true, 
     warnings: true, 
    }, 
    stats: 'errors-only', 
    }, 
}); 

exports.generateSourceMaps = ({ type }) => ({ 
    devtool: type, 
}); 

exports.loadCSS =() => ({ 
    module:{ 
    loaders: [{ 
     test: /\.css$/, 
     loader: ['style-loader','css-loader'], 
    }], 
    }, 
}); 

exports.loadJSX =() => ({ 
    module:{ 
    loaders: [{ 
     test: /\.(js|jsx)$/, 
     exclude: '/node_modules/', 
     loader: 'babel-loader', 
    }], 
    }, 
}); 

exports.loadSASS = (path) => ({ 
    module: { 
    loaders: [{ 
     test: /\.(css|sass|scss)$/, 
     loader: ETP.extract({ 
     fallback: 'style-loader', 
     use: 'css-loader!postcss-loader!sass-loader', 
     }), 
     include: path, 
    }], 
    }, 
}); 


exports.purifyCSS = ({ paths }) => (new PurifyCSSPlugin({paths})) 

回答

0

您在進入物業寫「賣主」,而不是「供應商」

+0

感謝用來捕獲錯誤。這是解決我遇到的另一個問題,但CSS仍然丟失,並沒有呈現給頁面。如果我將內容的供應商部分註釋掉了, –