Webpack css-loader configuration -
how configure webpack config resolve fonts inside node_modules/admin-lte/dist/fonts/source-sans-pro?
if execute npm run build
, file-loader places fonts inside dist/files folder series of error occurs, saying can't resolve font aliases made.
project directory
admin-lte node_module directory
webpack config
var path = require('path') var webpack = require('webpack') var inproduction = (process.env.node_env === 'production'); var indevelopment = (process.env.node_env === 'development'); var glob = require('glob'); var extracttextplugin = require('extract-text-webpack-plugin'); var extractless = new extracttextplugin('stylesheets/style-less.css'); var extractcss = new extracttextplugin('stylesheets/style-css.css'); module.exports = { entry: './src/main.js', output: { path: path.resolve(__dirname, './dist'), publicpath: './dist/', filename: 'build.js' }, module: { rules: [ { test: /\.vue$/, loader: 'vue-loader', options: { loaders: { } // other vue-loader options go here } }, { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }, { test: /\.less$/, use: extractless.extract( { use: [ { loader: 'css-loader', options: { alias: { "../../dist/fonts/source-sans-pro": "admin-lte/dist/files" } } }, { loader: 'less-loader', options: { includepaths: [ path.resolve("./node_modules/admin-lte/less") ] } } ], fallback: 'style-loader' } ) }, { test: /\.css$/, use: extractcss.extract( { use: [ { loader: 'css-loader', options: { url : true } } ], fallback: 'style-loader' } ) }, { test: /\.(png|jpe?g|gif|svg|eot|ttf|woff|woff2)?$/, loader: 'file-loader', options: { name: 'files/[name].[ext]?[hash]' } } ] }, plugins: [ extractcss, extractless, new webpack.provideplugin({ $: 'admin-lte/plugins/jquery/jquery-2.2.3.min.js', jquery: 'admin-lte/plugins/jquery/jquery-2.2.3.min.js', 'window.jquery': 'admin-lte/plugins/jquery/jquery-2.2.3.min.js', tether: 'tether', tether: 'tether', 'window.tether': 'tether', }) ], resolve: { alias: { 'vue$': 'vue/dist/vue.js' } }, devserver: { historyapifallback: true, noinfo: true }, performance: { hints: false }, devtool: '#eval-source-map' } if (inproduction) { module.exports.devtool = '#source-map' // http://vue-loader.vuejs.org/en/workflow/production.html module.exports.plugins = (module.exports.plugins || []).concat([ new webpack.defineplugin({ 'process.env': { node_env: '"production"' } }), new webpack.optimize.uglifyjsplugin({ sourcemap: true, compress: { warnings: false } }), new webpack.loaderoptionsplugin({ minimize: inproduction }) ]) }
Comments
Post a Comment