0

我创建了一个带有 angular material2 组件的 angular2 项目。现在我想自定义我的主题,所以我使用了webpack模块,因为这将从所有 scss 文件中创建一个文件,所以我习惯于extract-text-webpack-plugin创建单个文件。

这是我的webpack.config.js

var path = require('path')
var webpack = require('webpack')
var ExtractTextPlugin = require("extract-text-webpack-plugin");
// multiple extract instances
let extractCSS = new ExtractTextPlugin('[name].css');

module.exports = {
    entry: [
        '/src/assets/theme/'
    ],
    output: {
        path: path.join(__dirname, 'dist'),
        filename: 'index.js',
        publicPath: '/dist/'
    },

    module: {
        loaders: [
            { test: /\.scss$/i, loader: extractCSS.extract(['css', 'sass']) }
        ]
    },
    plugins: [
        extractCSS
    ]
}

这是我的 package.json 中的脚本

"build:css": "webpack --config webpack.config.js"

和运行的命令

npm run build:css

但这显示

> webpack --config webpack.config.js

Hash: a5e945c400552ce5350f
Version: webpack 3.3.0
Time: 68ms
   Asset    Size  Chunks             Chunk Names
index.js  2.6 kB       0  [emitted]  main
   [0] multi /src/assets/theme/ 28 bytes {0} [built]

ERROR in multi /src/assets/theme/
Module not found: Error: Can't resolve '/src/assets/theme/' in 'D:\Workspace\WebAdmin_Blade_Template_Material2\webapp'
 @ multi /src/assets/theme/

npm ERR! Windows_NT 10.0.14393
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build:css"
npm ERR! node v6.9.5
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! webapp@1.0.0 build:css: `webpack --config webpack.config.js`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the webapp@1.0.0 build:css script 'webpack --config webpack.config.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the webapp package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     webpack --config webpack.config.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs webapp
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls webapp
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:

问题出在entry,但无法解决?问题是什么?我错过了什么吗?

已编辑

我在 src/assets/theme/中缺少index.js 。这是这个文件的内容

require('./theme.scss');
require('./custom.scss');

并安装css-loadersass-loader

为了改变这个工作

loaders: [
                { test: /\.scss$/i, loader: extractCSS.extract(['css', 'sass']) }
            ]

而不是 CSS 和 sass 到 css-loader 和 sass-loader。

问题是,它是从 /dist/main.css 文件中的所有 sccss 文件创建一个文件。如何为每个 scss 文件创建单独的文件?

4

0 回答 0