Commit d4ee03d2 by hank

资源路径

parent 42433693
...@@ -15,11 +15,12 @@ exports.assetsPath = function (_path) { ...@@ -15,11 +15,12 @@ exports.assetsPath = function (_path) {
exports.cssLoaders = function (options) { exports.cssLoaders = function (options) {
options = options || {} options = options || {}
// console.log(options)
const cssLoader = { const cssLoader = {
loader: 'css-loader', loader: 'css-loader',
options: { options: {
sourceMap: options.sourceMap sourceMap: options.sourceMap,
publicPath: '../../'
} }
} }
...@@ -33,12 +34,13 @@ exports.cssLoaders = function (options) { ...@@ -33,12 +34,13 @@ exports.cssLoaders = function (options) {
// generate loader string to be used with extract text plugin // generate loader string to be used with extract text plugin
function generateLoaders (loader, loaderOptions) { function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader] const loaders = options.usePostCSS ? [cssLoader, postcssLoader] : [cssLoader]
// console.log('aaaa')
if (loader) { if (loader) {
loaders.push({ loaders.push({
loader: loader + '-loader', loader: loader + '-loader',
options: Object.assign({}, loaderOptions, { options: Object.assign({}, loaderOptions, {
sourceMap: options.sourceMap sourceMap: options.sourceMap,
publicPath: '.../../'
}) })
}) })
} }
...@@ -46,7 +48,13 @@ exports.cssLoaders = function (options) { ...@@ -46,7 +48,13 @@ exports.cssLoaders = function (options) {
// Extract CSS when that option is specified // Extract CSS when that option is specified
// (which is the case during production build) // (which is the case during production build)
if (options.extract) { if (options.extract) {
// console.log(MiniCssExtractPlugin.loader)
return [MiniCssExtractPlugin.loader].concat(loaders) return [MiniCssExtractPlugin.loader].concat(loaders)
// return ExtractTextPlugin.extract({
// use: loaders,
// fallback: 'vue-style-loader',
// publicPath: '../../'
// })
} else { } else {
return ['vue-style-loader'].concat(loaders) return ['vue-style-loader'].concat(loaders)
} }
......
...@@ -5,7 +5,6 @@ const isProduction = process.env.NODE_ENV === 'production' ...@@ -5,7 +5,6 @@ const isProduction = process.env.NODE_ENV === 'production'
const sourceMapEnabled = isProduction const sourceMapEnabled = isProduction
? config.build.productionSourceMap ? config.build.productionSourceMap
: config.dev.cssSourceMap : config.dev.cssSourceMap
module.exports = { module.exports = {
loaders: utils.cssLoaders({ loaders: utils.cssLoaders({
sourceMap: sourceMapEnabled, sourceMap: sourceMapEnabled,
......
'use strict' "use strict";
const path = require('path') const path = require("path");
const utils = require('./utils') const utils = require("./utils");
const config = require('../config') const config = require("../config");
const vueLoaderConfig = require('./vue-loader.conf') const vueLoaderConfig = require("./vue-loader.conf");
// const MiniCssExtractPlugin = require("mini-css-extract-plugin");
function resolve(dir) { function resolve(dir) {
return path.join(__dirname, '..', dir) return path.join(__dirname, "..", dir);
} }
const createLintingRule = () => ({ const createLintingRule = () => ({
test: /\.(js|vue)$/, test: /\.(js|vue)$/,
loader: 'eslint-loader', loader: "eslint-loader",
enforce: 'pre', enforce: "pre",
include: [resolve('src'), resolve('test')], include: [resolve("src"), resolve("test")],
options: { options: {
formatter: require('eslint-friendly-formatter'), formatter: require("eslint-friendly-formatter"),
emitWarning: !config.dev.showEslintErrorsInOverlay emitWarning: !config.dev.showEslintErrorsInOverlay
} }
}) });
module.exports = { module.exports = {
context: path.resolve(__dirname, '../'), context: path.resolve(__dirname, "../"),
entry: { entry: {
app: './src/main.js' app: "./src/main.js"
}, },
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
filename: '[name].js', filename: "[name].js",
publicPath: process.env.NODE_ENV === 'production' publicPath:
process.env.NODE_ENV === "production"
? config.build.assetsPublicPath ? config.build.assetsPublicPath
: config.dev.assetsPublicPath : config.dev.assetsPublicPath
}, },
resolve: { resolve: {
extensions: ['.js', '.vue', '.json'], extensions: [".js", ".vue", ".json"],
alias: { alias: {
'vue$': 'vue/dist/vue.esm.js', vue$: "vue/dist/vue.esm.js",
'@': resolve('src'), "@": resolve("src"),
'src': resolve('src') src: resolve("src")
} }
}, },
module: { module: {
...@@ -43,46 +45,49 @@ module.exports = { ...@@ -43,46 +45,49 @@ module.exports = {
// ...(config.dev.useEslint ? [createLintingRule()] : []), // ...(config.dev.useEslint ? [createLintingRule()] : []),
{ {
test: /\.vue$/, test: /\.vue$/,
loader: 'vue-loader', loader: "vue-loader",
options: vueLoaderConfig options: vueLoaderConfig
}, },
{ {
test: /\.js$/, test: /\.js$/,
loader: 'babel-loader', loader: "babel-loader",
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')] include: [
resolve("src"),
resolve("test"),
resolve("node_modules/webpack-dev-server/client")
]
}, },
{ {
test: /\.svg$/, test: /\.svg$/,
loader: 'svg-sprite-loader', loader: "svg-sprite-loader",
exclude: path.resolve(__dirname, './src/assets/icons'), exclude: path.resolve(__dirname, "./src/assets/icons"),
include: [resolve('src/icons')], include: [resolve("src/icons")],
options: { options: {
symbolId: 'icon-[name]' symbolId: "icon-[name]"
} }
}, },
{ {
test: /\.(png|jpe?g|gif)(\?.*)?$/, test: /\.(png|jpe?g|gif)(\?.*)?$/,
loader: 'url-loader', loader: "url-loader",
options: { options: {
limit: 10000, limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]') name: utils.assetsPath("img/[name].[hash:7].[ext]")
} }
}, },
{ {
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader', loader: "url-loader",
options: { options: {
limit: 10000, limit: 10000,
name: utils.assetsPath('media/[name].[hash:7].[ext]') name: utils.assetsPath("media/[name].[hash:7].[ext]")
} }
}, },
{ {
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader', loader: "url-loader",
options: { options: {
limit: 10000, limit: 10000,
name: utils.assetsPath('fonts/[name].[hash:7].[ext]') name: utils.assetsPath("fonts/[name].[hash:7].[ext]")
} }
} }
] ]
...@@ -93,10 +98,10 @@ module.exports = { ...@@ -93,10 +98,10 @@ module.exports = {
setImmediate: false, setImmediate: false,
// prevent webpack from injecting mocks to Node native modules // prevent webpack from injecting mocks to Node native modules
// that does not make sense for the client // that does not make sense for the client
dgram: 'empty', dgram: "empty",
fs: 'empty', fs: "empty",
net: 'empty', net: "empty",
tls: 'empty', tls: "empty",
child_process: 'empty' child_process: "empty"
} }
} };
...@@ -20,7 +20,8 @@ const env = ...@@ -20,7 +20,8 @@ const env =
// console.log(webpack.optimize); // console.log(webpack.optimize);
const webpackConfig = merge(baseWebpackConfig, { const webpackConfig = merge(baseWebpackConfig, {
module: { module: {
rules: utils.styleLoaders({ rules: utils
.styleLoaders({
sourceMap: config.build.productionSourceMap, sourceMap: config.build.productionSourceMap,
extract: true, extract: true,
usePostCSS: true usePostCSS: true
...@@ -60,9 +61,7 @@ const webpackConfig = merge(baseWebpackConfig, { ...@@ -60,9 +61,7 @@ const webpackConfig = merge(baseWebpackConfig, {
"process.env": env "process.env": env
}), }),
new WriteJsonPlugin({ new WriteJsonPlugin({
object: { object: {},
},
path: "", path: "",
// default output is timestamp.json // default output is timestamp.json
filename: "data.json", filename: "data.json",
......
...@@ -49,8 +49,9 @@ module.exports = { ...@@ -49,8 +49,9 @@ module.exports = {
// Paths // Paths
assetsRoot: path.resolve(__dirname, '../dist'), assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static', assetsSubDirectory: '../../static',
assetsPublicPath: './', assetsPublicPath: './',
publicPath: '../../',
/** /**
* Source Maps * Source Maps
...@@ -59,7 +60,7 @@ module.exports = { ...@@ -59,7 +60,7 @@ module.exports = {
productionSourceMap: false, productionSourceMap: false,
// https://webpack.js.org/configuration/devtool/#production // https://webpack.js.org/configuration/devtool/#production
devtool: '#source-map', devtool: '#source-map',
inlineSource: true, inlineSource: false,
// Gzip off by default as many popular static hosts such as // Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you. // Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to: // Before setting to `true`, make sure to:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment