如何使用带入口的materialize-loader作为对象?

时间:2016-08-23 18:16:41

标签: javascript webpack

在提供materialize-loader个自定义配置的文档中,它提到:

module.exports = {
  entry: [
    "materialize-loader!./path/to/materialize.config.js",
    "your-existing-entry-point"
  ]
};

但是当你的条目是一个对象时,如何导入它呢?我试过了"materialize-loader": "materialize-loader!./src/materialize.config.js",但它不起作用。我的materialize.config.scss文件中的自定义配置未获得应用。

我的网站包装如下:

var webpack = require("webpack");
var path = require("path");
var CopyWebpackPlugin = require('copy-webpack-plugin');

// Webpack Config
var webpackConfig = {
    entry: {
        "polyfills": "./src/polyfills.browser.ts",
        "vendor": "./src/vendor.browser.ts",
        "main": "./src/main.browser.ts"
    },

    output: {
        path: "./dist"
    },

    plugins: [
        new webpack.optimize.OccurenceOrderPlugin(true),
        new webpack.optimize.CommonsChunkPlugin({
            name: ["main", "vendor", "polyfills"],
            minChunks: Infinity
        }),
        new webpack.ProvidePlugin({
            jQuery: "jquery",
            $: "jquery",
            jquery: "jquery"
        }),
        new CopyWebpackPlugin([{
            from: 'src/app/images',
            to: 'images'
        }])
    ],

    module: {
        loaders: [
            // Load typescript
            {
                test: /\.ts$/, 
                loaders: ["awesome-typescript-loader", "angular2-template-loader"]
            },
            // Load css
            {
                test: /\.css$/, 
                loaders: ["to-string-loader", "css-loader"]
            },
            // Load html
            {
                test: /\.html$/, 
                loader: "raw-loader"
            },
            // Load scss
            {
                test: /\.scss$/, 
                loaders: ["raw-loader", "sass-loader"]
            },
            // Load woff fonts
            {
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                loader: "url?limit=10000&mimetype=application/font-woff"
            },
            // Load other fonts
            {
                test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, 
                loader: "file"
            }
        ]
    }

};


// Our Webpack Defaults
var defaultConfig = {
    devtool: "cheap-module-source-map",
    cache: true,
    debug: true,
    output: {
        filename: "[name].bundle.js",
        sourceMapFilename: "[name].map",
        chunkFilename: "[id].chunk.js"
    },

    resolve: {
        root: [path.join(__dirname, "src")],
        extensions: ["", ".ts", ".js"]
    },

    devServer: {
        historyApiFallback: true,
        watchOptions: {aggregateTimeout: 300, poll: 1000}
    },

    node: {
        global: 1,
        crypto: "empty",
        module: 0,
        Buffer: 0,
        clearImmediate: 0,
        setImmediate: 0
    }
};

var webpackMerge = require("webpack-merge");
module.exports = webpackMerge(defaultConfig, webpackConfig);

1 个答案:

答案 0 :(得分:0)

Answered by Zevran

entry: {
        "polyfills": "./src/polyfills.browser.ts",
        "vendor": [
            "materialize-loader!./path/to/materialize.config.js",
            "./src/vendor.browser.ts"
        ],
        "main": "./src/main.browser.ts"
    },