2016-10-30 3 views
1

클라이언트 측과 서버 측에서 폴더를 분할했지만 상위 폴더에서 작업하지 못했습니다. 두 개의 다른 것처럼 작동합니다. 폴더 ... 지금은 Heroku에 배포하고 싶지만 그 때문에 내 새 루트 폴더에서 스크립트를 실행할 수 있도록 webpack.config를 변경하려고 한 주 폴더가 필요합니다. 나는 나에게 도움이되지 않았다 이러한 솔루션을 시도, 내가 해결하기 위해 알아낼 수있는 마지막 오류를 받고 있어요 중 하나ERROR in ./~ /constants-browserify/constants.json

ERROR in ./~/constants-browserify/constants.json 
Module parse failed: /Users/Documents/Twitch/testbot/node_modules/constants-browserify/constants.json Unexpected token (2:12) 
You may need an appropriate loader to handle this file type. 
| { 
| "O_RDONLY": 0, 
| "O_WRONLY": 1, 
| "O_RDWR": 2, 
@ ./src/js/reducers/chat.js 1:0-50 
@ ./src/js/script.js 
@ multi main 

: First, Second

이것은 내가지고있어 오류입니다 이 오류

import {CHAT_MESSAGE_RECEIVED} from 'constants'; 

const chatReducer = (state = [], action) => { 
    switch(action.type){ 
    case CHAT_MESSAGE_RECEIVED: 
    console.log(state, action); 
    return [...state, action.payload]; 

    default: 
    return state; 
    } 
}; 

export default chatReducer; 
,536에 나와있는 감속기는

// changed some loader syntax after reading 
// https://webpack.js.org/how-to/upgrade-from-webpack-1/ 

const path = require(`path`); 

const webpack = require(`webpack`); 
const {UglifyJsPlugin} = webpack.optimize; 

const CopyWebpackPlugin = require(`copy-webpack-plugin`); 
const ExtractTextWebpackPlugin = require(`extract-text-webpack-plugin`); 
const configHtmls = require(`webpack-config-htmls`)(); 

const extractCSS = new ExtractTextWebpackPlugin(`css/style.css`); 

// change for production build on different server path 
const publicPath = `/`; 

// hard copy assets folder for: 
// - srcset images (not loaded through html-loader) 
// - json files (through fetch) 
// - fonts via WebFontLoader 

const copy = new CopyWebpackPlugin([{ 
    from: `./src/assets`, 
    to: `assets` 
}], { 
    ignore: [ `.DS_Store` ] 
}); 

const config = { 

    entry: [ 
    `./src/css/style.css`, 
    `./src/js/script.js` 
    ], 

    resolve: { 
    // import files without extension import ... from './Test' 
    extensions: [`.js`, `.jsx`, `.css`] 
    }, 

    output: { 
    path: path.join(__dirname, `server`, `public`), 
    filename: `js/[name].[hash].js`, 
    publicPath 
    }, 

    devtool: `sourcemap`, 

    module: { 

    rules: [ 
     { 
     test: /\.css$/, 
     loader: extractCSS.extract([ 
      { 
      loader: `css`, 
      options: { 
       importLoaders: 1 
      } 
      }, 
      { 
      loader: `postcss` 
      } 
     ]) 
     }, 
     { 
     test: /\.html$/, 
     loader: `html`, 
     options: { 
      attrs: [ 
      `audio:src`, 
      `img:src`, 
      `video:src`, 
      `source:srcset` 
      ] // read src from video, img & audio tag 
     } 
     }, 
     { 
     test: /\.(jsx?)$/, 
     exclude: /node_modules/, 
     use: [ 
      { 
      loader: `babel` 
      }, 
      { 
      loader: `eslint`, 
      options: { 
       fix: true 
      } 
      } 
     ] 
     }, 
     { 
     test: /\.(svg|png|jpe?g|gif|webp)$/, 
     loader: `url`, 
     options: { 
      limit: 1000, // inline if < 1 kb 
      context: `./src`, 
      name: `[path][name].[ext]` 
     } 
     }, 
     { 
     test: /\.(mp3|mp4)$/, 
     loader: `file`, 
     options: { 
      context: `./src`, 
      name: `[path][name].[ext]` 
     } 
     } 
    ] 

    }, 

    plugins: [ 
    extractCSS, 
    copy 
    ] 

}; 

if(process.env.NODE_ENV === `production`){ 

    //image optimizing 
    config.module.rules.push({ 
    test: /\.(svg|png|jpe?g|gif)$/, 
    loader: `image-webpack`, 
    enforce: `pre` 
    }); 

    config.plugins = [ 
    ...config.plugins, 
    new UglifyJsPlugin({ 
     sourceMap: true, // false returns errors.. -p + plugin conflict 
     comments: false 
    }) 
    ]; 

} 

config.plugins = [...config.plugins, ...configHtmls.plugins]; 

module.exports = config; 

: 그리고 이것은 내 webpack.config.js입니다

이 오류를 해결하기 위해 내가 잘못하고있는 것에 대한 아이디어가 있습니까?

+0

오류 메시지를 직접 질문에 붙여 넣으면 다른 사람들이 검색 할 때이 질문을 더 쉽게 찾을 수 있습니다 (이미지를로드 할 때까지 기다릴 필요가 없기 때문에 질문에 답변하는 사람들을위한 시간을 절약 할 수 있습니다) . – Aurora0001

+0

나는 내 질문에 오류의 첫 줄을 입력하여 그 일을했다고 생각 했습니까? 어떤 부분을 추가 하시겠습니까? 바로 편집하겠습니다. – Kevin

+0

터미널에있는 전체 오류 메시지 (현재 이미지로 사용하고 있음)를 의미했습니다. 그것은 단지 귀하의 질문에 그것을 가지고 더 나은 것으로 간주되므로 읽기 쉽고 이미지가 제거되면 링크 썩음으로 고통받을 수 없습니다. – Aurora0001

답변

3

경로가 '상수'인 파일을 가져 왔는데이 경로는 node_modules의 constants-browserify 폴더와 간섭하고있었습니다.

상수의 파일 이름과 경로를 변경하여 오류가 수정되었습니다.

+0

해상도 우선 순위를 설정할 수 있다면'constants-browserify' 대신'constants' 파일이 포함될 것입니다. –

+0

@LiubomyrMykhalchenko 그게 변경 될 웹팩 설정 일 뿐이라고 생각합니까? – Kevin

+0

예, 그렇게 생각합니다.하지만 정확히 무엇을 바꿔야 할지를 생각한 것 같습니다. 웹팩 설정으로 조금 놀았지만,'const.js'를'const.js'로 개명했습니다. –

관련 문제