如果这有什么不同,我会在 docker 容器中运行 webpack。
我的 webpack.config.js:
module.exports = {
entry: './app/Resources/scripts/test.js',
output: {
filename: './web/js/bundle.js'
},
watch: true,
module: {
rules: [{
test: /\.scss$/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader" // compiles Sass to CSS
}]
}]
}
}
我的 test.js:
require('../styles/test.scss');
alert('Hello');
我的文件结构:
app/
--Resources/
----scripts/
------test.js
----styles/
------test.scss
web/
--js/
----bundle.js
webpack.config.js
我的 dockerfile 是:
FROM ubuntu:latest
WORKDIR /app
RUN apt-get update
RUN apt-get install curl -y
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - && apt-get install nodejs -y
RUN npm install webpack sass-loader css-loader style-loader node-sass -g
CMD webpack
JS 编译正常,工作正常等。但是,当尝试编译 SCSS 时,它会失败并出现错误:
webpack_require (!(function webpackMissingModule() { var e = new Error("找不到模块\"../styles/test.scss\""); e.code = 'MODULE_NOT_FOUND'; throw e; }())) ;