Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twitter bootstrap 如何在使用webpack时将静态文件导入到assets目录的js中?_Twitter Bootstrap_Webpack - Fatal编程技术网

Twitter bootstrap 如何在使用webpack时将静态文件导入到assets目录的js中?

Twitter bootstrap 如何在使用webpack时将静态文件导入到assets目录的js中?,twitter-bootstrap,webpack,Twitter Bootstrap,Webpack,我有es6 angularjs应用程序,它在我的webpack.config.js文件中: plugins: [ new webpack.optimize.CommonsChunkPlugin({ name: "vendor", minChunks: function (module) { // this assumes your vendor imports exist in the node_modules directory

我有es6 angularjs应用程序,它在我的
webpack.config.js
文件中:

plugins: [
    new webpack.optimize.CommonsChunkPlugin({
        name: "vendor",
        minChunks: function (module) {
            // this assumes your vendor imports exist in the node_modules directory
            return module.context && module.context.indexOf("node_modules") !== -1;
        }
    }),
    new CopyWebpackPlugin([
        {from: 'favicon', to: 'favicon'},
        {from: 'index.html'},
        {from: 'rpc.php'},
        {from: 'json-rpc.php'},
        {from: '.htaccess'}
    ])
],
module: {
    loaders: [
        {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
                presets: ['env']
            }
        },
        {
            test: /jquery(\.min)?\.js$/,
            loader: 'expose-loader?jQuery'
        },
        {
            test: /\.html$/,
            loader: 'html-loader'
        },
        {
            test: /\.css$/,
            loaders: ['style-loader', 'css-loader']
        },
        {
            test: /\.(eot|woff2?|ttf|svg)$/,
            loader: 'file-loader'
        }
    ]
}
我的dist文件夹如下所示:

448c34a56d699c29117adc64c43affeb.woff2  e18bbf611f2a2e43afc071aa2f4e1512.ttf   index.html
89889688147bd7575d6327160d64e760.svg    f4769f9bdb7466be65088239c12046d1.eot   json-rpc.php
app.js                                  fa2772327f55d8198301fdb8bcfc8158.woff  rpc.php
dac34d70a97c4088841fb6f5f3d2df62.svg    favicon                                vendor.js

如何在assets目录中创建静态文件(由文件加载器加载),如字体或svg文件(一个来自其中一个文件中导入的图像,一个来自bootstrap)?

我需要添加
outputPath

{
    test: /\.(eot|woff2?|ttf|svg)$/,
    loader: 'file-loader?outputPath=/assets/'
}
对于webpack dev server,我还需要添加:

  "scripts": {
    "webpack": "NODE_ENV=production webpack",
    "serve": "NODE_ENV=development webpack-dev-server --hot"
  },
在package.json和webpack.config.js中:

{
    test: /\.(eot|woff2?|ttf|svg)$/,
    loader: 'file-loader' +
        (process.env.NODE_ENV == 'production' ? '?publicPath=assets/&outputPath=/assets/' : '')
}