React webpack - 设置脚本以构建项目

时间:2017-09-15 05:50:54

标签: reactjs webpack

如果我输入npm run start,则启动项目。如果输入npm run build存在,它会在import,webpack上抛出意外的令牌导入异常。

如何正确组装项目?

所有内容都收集在一个文件夹中。如果我运行index.html它会正常工作。

我的package.js:

{
  "name": "your-pizza",
  "version": "1.0.0",
  "description": "Order pizza Omsk",
  "scripts": {
    "start": "npm-run-all --parallel open:src lint:watch",
    "build": "webpack --config ./webpack.config.dev.js",
    "open:src": "babel-node tools/runServer.js",
    "lint": "node_modules/.bin/esw webpack.config.* src tools",
    "lint:watch": "npm run lint -- --watch"
  },
  ...
}

我的网站:

import webpack from 'webpack';
import path from 'path';
let ExtractTextPlugin = require('extract-text-webpack-plugin');

export default {
    debug: true,
    devtool: 'inline-source-map',
    noInfo: false,
    entry: [
        'eventsource-polyfill',
        'webpack-hot-middleware/client?reload=true',
        path.resolve(__dirname, 'src/index')
    ],
    target: 'web',
    output: {
        path: __dirname + '/dist',
        publicPath: '/',
        filename: 'bundle.js'
    },
    devServer: {
        contentBase: path.resolve(__dirname, 'src')
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ],
    module: {
        loaders: [
            {test: /\.js$/, include: path.join(__dirname, 'src'), loaders: ['babel']},
            {test: /(\.css)$/, loaders: ['style', 'css']},
            {test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file'},
            {test: /\.(woff|woff2)$/, loader: 'url?prefix=font/&limit=5000'},
            {test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream'},
            {test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml'},
            {test: /\.scss$/, loaders: ["style-loader", "css-loader", "sass-loader"]},
            {test: /bootstrap.+\.(jsx|js)$/, loader: 'imports?jQuery=jquery,$=jquery,this=>window'},
            {test: /\.(png|jpg|gif)$/, loader: 'url-loader'}
        ]
    }
}; 

0 个答案:

没有答案