2017-08-12 119 views
0

我正在嘗試使用webpack與我的asp.net mvc核心項目。我可以捆綁js文件。但我無法從scss文件中提取我的css。使用webpack從scss文件中提取css

var path = require('path'); 
var extractTextPlugin = require("extract-text-webpack-plugin"); 
var cleanWebpackPlugin = require('clean-webpack-plugin'); 

module.exports = { 
    entry: { 
     'role/role': './scripts/role/roleVM.ts', 
     main: './scripts/main.ts', 
     vendor: ["jquery"], 
    }, 
    output: { 
     filename: '[name].js', 
     path: path.resolve(__dirname, 'wwwroot/dist/js/') 
    }, 
    module: { 
     rules: [ 
      { 
       test: /\.tsx?$/, 
       loader: 'ts-loader', 
       exclude: /node_modules/, 
      }, 
      { 
       test: /\.scss$/, 
       use: extractTextPlugin.extract({ 
        use: [{ 
         loader: "css-loader", options: { 
          sourceMap: true 
         } 
        }, { 
         loader: "sass-loader", options: { 
          sourceMap: true 
         } 
        }], 
        fallback: 'style-loader' 
       }), 
       exclude: /node_modules/, 
      }, 
     ] 
    }, 
    plugins: [ 
     new cleanWebpackPlugin(['dist'], { 
      root: path.resolve(__dirname, 'wwwroot'), 
      verbose: true, 
      dry: false 
     }), 
     new extractTextPlugin("./css/main.css") 
    ], 
    resolve: { 
     extensions: [".tsx", ".ts", ".js", '.scss'] 
    } 
}; 
當我建立我的項目

,在CSS文件不創建

我的命令:

npm run build --color=always 
> [email protected] build C:\project\src\test 
> webpack 
clean-webpack-plugin: C:\project\src\project\wwwroot\dist has been removed. 
ts-loader: Using [email protected] and C:\project\src\project\tsconfig.json 
Hash: 2cdaff8d8177eedec094 
Version: webpack 3.5.3 
Time: 2203ms 
     Asset  Size Chunks     Chunk Names 
role/role.js 293 kB  0 [emitted] [big] role/role 
    vendor.js 271 kB  1 [emitted] [big] vendor 
    main.js 2.48 kB  2 [emitted]   main 
    [0] ./scripts/role/roleVM.ts 400 bytes {0} [built] 
    [2] ./scripts/main.ts 0 bytes {2} [built] 
    [3] multi jquery 28 bytes {1} [built] 

它看起來像它跳到通中提取文本插件。

從我的配置文件中缺少什麼?

我目前的項目結構:

└── Project 
    ├── wwwroot 
    │   └── scss 
    │  └── main.scss 
    └── scripts 
    │ └── main.ts 
    │ 
    └── webpack.config.js 
+1

你導入你的main.ts的.scss文件? –

回答

相關問題