Skip to content

Commit

Permalink
fix wxml relative path bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Cap32 committed Mar 2, 2018
1 parent 7712a74 commit f6413ba
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"eslint-plugin-node": "^4.2.2",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1",
"file-loader": "^0.11.2",
"file-loader": "1.1.11",
"glob": "^7.1.2",
"jest": "^20.0.4",
"node-sass": "^4.6.1",
Expand All @@ -63,7 +63,7 @@
"webpack": "^3.8.1",
"webpack-dashboard": "^1.0.0",
"wxapp-webpack-plugin": "^0.17.1",
"wxml-loader": "^0.1.2"
"wxml-loader": "^0.2.0"
},
"dependencies": {
"babel-runtime": "^6.23.0",
Expand Down
37 changes: 14 additions & 23 deletions webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,16 @@ import MinifyPlugin from 'babel-minify-webpack-plugin';
const { NODE_ENV, LINT } = process.env;
const isDev = NODE_ENV !== 'production';
const shouldLint = !!LINT && LINT !== 'false';
const srcDir = resolve('src');

const relativeFileLoader = (ext = '[ext]') => [
{
loader: 'file-loader',
options: {
publicPath: '',
useRelativePath: true,
name: `[name].${ext}`,
emitFile: false
}
},
{
loader: 'file-loader',
options: {
publicPath: '',
context: resolve('src'),
name: `[path][name].${ext}`
}
const relativeFileLoader = (ext = '[ext]') => ({
loader: 'file-loader',
options: {
useRelativePath: true,
name: `[name].${ext}`,
context: srcDir
}
];
});

export default (env = {}) => {
const min = env.min;
Expand Down Expand Up @@ -66,7 +56,7 @@ export default (env = {}) => {
include: /src/,
exclude: /node_modules/,
use: [
...relativeFileLoader(),
relativeFileLoader(),
'babel-loader',
shouldLint && 'eslint-loader'
].filter(Boolean)
Expand All @@ -75,7 +65,7 @@ export default (env = {}) => {
test: /\.scss$/,
include: /src/,
use: [
...relativeFileLoader('wxss'),
relativeFileLoader('wxss'),
{
loader: 'sass-loader',
options: {
Expand All @@ -93,11 +83,12 @@ export default (env = {}) => {
test: /\.wxml$/,
include: resolve('src'),
use: [
...relativeFileLoader(isWechat ? 'wxml' : 'axml'),
relativeFileLoader(isWechat ? 'wxml' : 'axml'),
{
loader: 'wxml-loader',
options: {
root: resolve('src')
root: resolve('src'),
enforceRelativePath: true
}
}
]
Expand All @@ -121,7 +112,7 @@ export default (env = {}) => {
new IgnorePlugin(/vertx/),
isDev && new DashboardPlugin(),
shouldLint && new StylelintPlugin(),
min && new MinifyPlugin(),
min && new MinifyPlugin()
].filter(Boolean),
devtool: isDev ? 'source-map' : false,
resolve: {
Expand Down
32 changes: 26 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ ajv-keywords@^2.0.0:
version "2.1.0"
resolved "http://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-2.1.0.tgz#a296e17f7bfae7c1ce4f7e0de53d29cb32162df0"

ajv-keywords@^3.1.0:
version "3.1.0"
resolved "http://registry.npm.taobao.org/ajv-keywords/download/ajv-keywords-3.1.0.tgz#ac2b27939c543e95d2c06e7f7f5c27be4aa543be"

ajv@^4.7.0, ajv@^4.9.1:
version "4.11.5"
resolved "http://registry.npm.taobao.org/ajv/download/ajv-4.11.5.tgz#b6ee74657b993a01dce44b7944d56f485828d5bd"
Expand All @@ -105,6 +109,14 @@ ajv@^5.3.0:
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

ajv@^6.1.0:
version "6.2.0"
resolved "http://registry.npm.taobao.org/ajv/download/ajv-6.2.0.tgz#afac295bbaa0152449e522742e4547c1ae9328d2"
dependencies:
fast-deep-equal "^1.0.0"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "http://registry.npm.taobao.org/align-text/download/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
Expand Down Expand Up @@ -2735,11 +2747,12 @@ file-entry-cache@^2.0.0:
flat-cache "^1.2.1"
object-assign "^4.0.1"

file-loader@^0.11.2:
version "0.11.2"
resolved "http://registry.npm.taobao.org/file-loader/download/file-loader-0.11.2.tgz#4ff1df28af38719a6098093b88c82c71d1794a34"
file-loader@1.1.11:
version "1.1.11"
resolved "http://registry.npm.taobao.org/file-loader/download/file-loader-1.1.11.tgz#6fe886449b0f2a936e43cabaac0cdbfb369506f8"
dependencies:
loader-utils "^1.0.2"
schema-utils "^0.4.5"

filename-regex@^2.0.0:
version "2.0.0"
Expand Down Expand Up @@ -5606,6 +5619,13 @@ sax@^1.2.1, sax@^1.2.2:
version "1.2.2"
resolved "http://registry.npm.taobao.org/sax/download/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828"

schema-utils@^0.4.5:
version "0.4.5"
resolved "http://registry.npm.taobao.org/schema-utils/download/schema-utils-0.4.5.tgz#21836f0608aac17b78f9e3e24daff14a5ca13a3e"
dependencies:
ajv "^6.1.0"
ajv-keywords "^3.1.0"

scss-tokenizer@^0.2.3:
version "0.2.3"
resolved "http://registry.npm.taobao.org/scss-tokenizer/download/scss-tokenizer-0.2.3.tgz#8eb06db9a9723333824d3f5530641149847ce5d1"
Expand Down Expand Up @@ -6671,9 +6691,9 @@ wxapp-webpack-plugin@^0.17.1:
lodash "^4.17.4"
webpack-sources "^0.2.3"

wxml-loader@^0.1.2:
version "0.1.2"
resolved "http://registry.npm.taobao.org/wxml-loader/download/wxml-loader-0.1.2.tgz#f14e19c0951ffbbcc730755a9b4ff1a5fde11a7d"
wxml-loader@^0.2.0:
version "0.2.0"
resolved "http://registry.npm.taobao.org/wxml-loader/download/wxml-loader-0.2.0.tgz#45bf9adb95b8b165bba76972b0a2a8dd25220321"
dependencies:
html-minifier "^3.5.6"
loader-utils "^1.1.0"
Expand Down

0 comments on commit f6413ba

Please sign in to comment.