Sass加载器挂起编译

时间:2018-04-13 13:58:40

标签: node.js angular webpack node-sass sass-loader

我使用的是webpack 2.2.0和sass-loader 4.4.1,@ angular / core是2.4.4

当我运行命令:npm run serve时,它会使62%的挂起命令提示符有时为61%或63%。 下面是package.json的id dev依赖项:

  "devDependencies": {
    "@types/core-js": "0.9.35",
    "@types/googlemaps": "3.26.2",
    "@types/node": "6.0.60",
    "@types/uglify-js": "2.0.27",
    "angular2-template-loader": "0.4.0",
    "awesome-typescript-loader": "2.2.4",
    "copy-webpack-plugin": "3.0.1",
    "css-loader": "0.25.0",
    "exports-loader": "0.6.3",
    "file-loader": "0.9.0",
    "html-webpack-plugin": "2.26.0",
    "imports-loader": "0.6.5",
    "json-loader": "0.5.4",
    "metrojs": "0.9.77",
    "napa": "2.3.0",
    "node-sass": "4.2.0",
    "raw-loader": "0.5.1",
    "resolve-url-loader": "1.6.1",
    "rimraf": "2.5.4",
    "sass-loader": "4.1.1",
    "sass-to-js": "1.3.0",
    "source-map-loader": "0.1.6",
    "style-loader": "0.13.1",
    "ts-helpers": "1.1.2",
    "typedoc": "0.4.5",
    "typescript": "2.0.2",
    "url-loader": "0.5.7",
    "webpack": "2.2.0",
    "webpack-dashboard": "0.2.1",
    "webpack-dev-middleware": "1.9.0",
    "webpack-dev-server": "2.2.0",
    "webpack-md5-hash": "0.0.5",
    "webpack-merge": "2.4.0"
  },

以下是webpack.common.js文件的代码。

const webpack = require('webpack');
const helpers = require('./helpers');

const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkCheckerPlugin = require('awesome-typescript-loader').ForkCheckerPlugin;
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

const METADATA = {
  title: 'Azimuth - Angular 2 Admin Template',
  description: 'Admin template based on Angular 2, Bootstrap 4 and Webpack',
  baseUrl: './'
};

module.exports = {

    entry: {
        'polyfills': './src/polyfills.ts',
        'vendor': './src/vendor.ts',
        'main': './src/main.ts'
    },

    resolve:{
        extensions: ['.js', '.ts', '.css', '.scss', '.json'],
        modules: [helpers.root('src'), 'node_modules']
    },

    module: {       
        loaders:[ 
             {
                test: /\.ts$/,
                loaders: [
                    'awesome-typescript-loader',
                    'angular2-template-loader'
                ],
                exclude: [/\.(spec|e2e)\.ts$/]
             },
             {
                test: /\.json$/,
                loader: 'json-loader'
             },
             {
                test: /\.css$/,
                loader: 'raw-loader'
             },
             {
                test: /\.scss$/,
                loaders: ['raw-loader', 'sass-loader'] // here if i comment sass-loader then worked.
             },
             {
                test: /initial\.scss$/,                
                loader: ExtractTextPlugin.extract({
                    fallbackLoader: 'style-loader',
                    loader: 'css-loader!sass-loader?sourceMap'
                })
             },

             {
                test: /\.woff(2)?(\?v=.+)?$/,
                loader: 'url-loader?limit=10000&mimetype=application/font-woff&name=fonts/[name].[ext]'
             },

             {
                test: /\.(ttf|eot|svg)(\?v=.+)?$/,
                loader: 'file-loader?&name=fonts/[name].[ext]'
             },
             {
                test: /bootstrap\/dist\/js\/umd\//,
                loader: 'imports?jQuery=jquery'
             },
             {
                test: /\.html$/,
                loader: 'raw-loader',
                exclude: [helpers.root('src/index.html')]
             },  
             { 
                 test: /\.(png|jpg|gif)$/,
                 loader: 'file-loader?limit=8192&name=assets/img/[name].[ext]'
             }           
        ]
    },

    plugins:[
        new ExtractTextPlugin({filename: 'initial.css', allChunks: true}),
        new ForkCheckerPlugin(),

        new ContextReplacementPlugin(
            /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
            helpers.root('src')
        ),


        new webpack.optimize.CommonsChunkPlugin({
            name: ['polyfills', 'vendor'].reverse()
        }),
        new CopyWebpackPlugin([{
            from: 'src/assets',
            to: 'assets'
        }]),
        new HtmlWebpackPlugin({
            title: METADATA.title,
            template: 'src/index.html',
            chunksSortMode: 'dependency',
            metadata: METADATA
        }), 
        new webpack.ProvidePlugin({
            jQuery: "jquery",
            $: 'jquery',
            jquery: 'jquery',
            'window.jQuery': 'jquery',
            'Tether': 'tether',
            'window.Tether': 'tether',
            Datamap:'datamaps',
            Skycons: 'skycons/skycons',
            Dropzone: 'dropzone',
            moment: 'moment',
            fullCalendar: 'fullcalendar'
        })

    ],

     node: {
        global: true,
        crypto: 'empty',
        process: true,
        module: false,
        clearImmediate: false,
        setImmediate: false
    }
}

如果我在

中评论sass-loader

loaders: ['raw-loader', 'sass-loader']

行并使用

loaders: ['raw-loader', 'css-loader', 'style-loader']

然后它会跳过挂起但css不会出现。

我已尝试更新package.json文件中的所有模块,但没有任何帮助。我不知道为什么会挂起来。版本中是否存在兼容性问题?

0 个答案:

没有答案